Reputation: 2511
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?
Upvotes: 3
Views: 2363
Reputation: 431
You need to use scale_x_continuous
to achieve what you want since your x axis is not discrete. 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))
Upvotes: 6