r - ggplot 将图例中的符号覆盖为直线

标签 r ggplot2

我只想在图例中显示线条(而不是十字)。 picture of plot with cross

 example.dat <- data.frame(distance=c("short","medium","short","medium"),ubiquity = c(0.09,0.09,0.30,0.30),deltaAUC = c(-0.0095,-0.039,-0.0206,-0.045),lower=c(-0.0888,0.0299,-0.0089,0.09),upper=c(0.165,0.284,0.174,0.273))

ggplot(example.dat, aes(ubiquity, deltaAUC,colour=distance)) + 
 geom_line(aes(group=distance),size=1,position=position_dodge(0.02))+
geom_point(position=position_dodge(0.02),size=0)+
geom_linerange(aes(ymin=-(plogis(lower)-0.5), ymax=- (plogis(upper)-0.5)),position=position_dodge(0.02),size=1)+
theme_bw()+
theme(plot.title=element_text(margin=margin(t=40,b=-20),hjust=0.5),
    legend.position = c(0.8, 0.2),
    legend.background = element_rect(color = "black",size = .3),
    legend.title=element_blank())+
guides(colour = guide_legend(override.aes = list(shape=0,linetype=1)))+
ggtitle(NULL)+
ylab(NULL)+
xlab(NULL)

最佳答案

show.legend = FALSE 添加到您不需要图例的 geom,例如:

geom_linerange(aes(ymin = -(plogis(lower)-0.5), ymax = - (plogis(upper)-0.5)), 
               position = position_dodge(0.02), 
               size = 1, 
               show.legend = FALSE)

关于r - ggplot 将图例中的符号覆盖为直线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51050279/

相关文章:

r - 在 R 中构建分类变量的移动平均值

r - 通过名称模糊匹配创建唯一 ID(通过使用 R 的 agrep)

r - 单个 block 内可变的绘图高度

r - 评估正则表达式模式是否总是与另一个模式匹配或更多

python - R 优化与 Scipy 优化之间的差异 : Nelder-Mead

r - RSelenium:连接被拒绝错误

R - 如何修改图例?

使用 ggplot2 从 geom_rect 中删除边框

r - 在 ggplot2 中跨几何均匀应用抖动

r - 在ggplot2中使用geom_violin将统计信息传递给geoms