繁体   English   中英

R:geom_segment ggplot2中的线条粗细不一致

[英]R:Inconsistent line thickness in geom_segment ggplot2

我正在尝试使用ggplot2在直方图底部的一些线段,覆盖几个线段以指示分布的相关部分。 我希望绿色部分的厚度是灰色部分的两倍,但绿色部分似乎总是灰色部分厚度的五倍。 这是一些玩具数据和我的ggplot2代码:

library(ggplot2)
x<- as.data.frame(rnorm(1000, mean=50))
colnames(x) <- c("values")

ggplot(x, aes(x=values)) +
geom_histogram (binwidth=1,position="identity", col="black")+
 theme_classic(base_size=18)+
theme(axis.line.x = element_line(colour = "black"),
axis.line.y = element_line(colour = "black"))+
geom_segment(aes(y=-10, yend=-10, col=I("darkgray"), size=.1,x=1, xend=100),show.legend=F)+
geom_segment(aes(y=-10, yend=-10, col=I("palegreen4"), size=.2,x=25,xend=75), show.legend=F)

而我的结果是: 在此输入图像描述

ggplot(x, aes(x=values)) +
  geom_histogram(binwidth=1, position="identity", col="black") +
  theme_classic(base_size=18) +
  geom_segment(aes(y=-10, yend=-10,x=1, xend=100), colour = "grey", size=1, show.legend=F) +
  geom_segment(aes(y=-10, yend=-10, x=25,xend=75), colour = "green", size = 2, show.legend=F)

尝试在你aes()调用之外移动size 只有随数据变化的变量才需要在aes() ,因此colour也会出现。 我清理了你的theme_axis adjustments因为我没有注意到对最终情节的明显影响。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM