2017-08-04 30 views
1

比方说,我有这样的情节如何添加x轴刻度和标签波纹管在GGPLOT2散点图每一点

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() 

这使得:

enter image description here

我怎样才能添加轴刻度和标签,以便每个点都有相应的刻度和标签?

回答

2

你需要使用scale_x_continuous来实现你想要的,因为你的X轴不是离散的。下面的代码应该可以工作:

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)) 
相关问题