[英]How to add x-axis ticks and labels bellow every point in a ggplot2 scatter plot
Let's say I have this plot 假设我有这个情节
iris2 <- iris %>% data.table
iris2 <- iris2[Sepal.Length<6]
iris2[,Sepal.Width:=mean(Sepal.Width),by=Sepal.Length]
iris2 %>% ggplot(aes(x=Sepal.Length,y=Sepal.Width,color=Species,group=Species)) +
geom_line() + geom_point()
Which renders: 呈现:
How can I add axis ticks and labels so that for every point there is a corresponding tick and label? 如何添加轴刻度和标签,以便每个点都有对应的刻度和标签?
You need to use scale_x_continuous
to achieve what you want since your x axis is not discrete. 由于x轴不是离散的,因此需要使用
scale_x_continuous
来实现所需的功能。 The following code should work: 下面的代码应该工作:
iris2 %>%
ggplot(aes(x = Sepal.Length, y = Sepal.Width, color = Species, group = Species)) +
geom_line() +
geom_point() +
scale_x_continuous(breaks = unique(iris$Sepal.Length))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.