'ggplot x-axis labels with all x-axis values
I'm plotting ggplot with geom_point. The x-axis will be individuals' ID, and y-axis is variable A. How can I ggplot all and individual ID values on the x-axis without overlapping labels? ID may not be continuous.
df sample (actual rows are much longer)
> df
ID A
1 4
2 12
3 45
5 1
Code for the plot:
ggplot(df, aes(x = ID, y = A)) + geom_point()
Above code has x-axis in intervals, but not presenting individual ID.
Thanks!
Solution 1:[1]
Just add + xlim() and + ylim() to show the full x axis and y axis (i.e. to make the x axis and y axis start at zero).
Reproducible example
If this is your ggplot:
iris %>%
ggplot(aes(x=Sepal.Length, y=Sepal.Width)) +
geom_point()
simply add these two lines to make the x and y axes start at zero:
iris %>%
ggplot(aes(x=Sepal.Length, y=Sepal.Width)) +
geom_point() +
xlim(0, 8.2) + # add this line for x axis limits
ylim(0, 4.5) # add this line for y axis limits
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |


