我目前正在使用ggplot2中的这些“棒棒糖”图。我正在尝试仅在显示观测值的地方绘制轴上的年值。所以我想这将是一个单独的轴格式,但是到目前为止我还找不到任何东西。我有很多这样的图要做-这就是为什么我手动标记红色的图。
有任何想法吗?
这是我的代码和情节:
# Create data
value1 <- c(33000000,45000000,45000000, 60000000,65000000,40000000)
value2 <- c(102984862,129342769,147717833,300228084,240159255,312242626)
value3 <- c(2002,2004,2007,2010,2012,2016)
data <- data.frame(value1=value1, value2=value2)
# Plot
ggplot(data) +
geom_segment( aes(x=value3, xend=value3, y=value1, yend=value2), color="grey") +
geom_point( aes(x=value3, y=value1), color=rgb(0.0,0.0,0.0,0.9), size=2 ) +
geom_point( aes(x=value3, y=value2), color=rgb(0.0,0.9,0.0,0.9), size=2 ) +
coord_flip()+
theme_grey() +
scale_y_continuous(name="", limits = c(0, 400000000)) +
theme(legend.position = "none",panel.grid.major = element_blank(), panel.grid.minor = element_blank(), axis.text.x = element_blank()) +
您可以添加:scale_x_continuous(breaks = value3)。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句