'how to translate x-axis plot code to ggplot code in R
I'm having troubles using this idea with ggplot2
axis(1, at=1:6, lab=c("Art", "Basic", "Comp", "Day", "Est", "Fin"))
how can I do this with the ggplot2 package? Thank you!
Solution 1:[1]
You would really need to show us the rest of your data and plotting code to get a full answer here, but an example would be:
library(ggplot2)
df <- data.frame(x = 1:6, y = c(5, 2, 3, 4, 6, 1))
ggplot(df, aes(x, y)) +
geom_point() +
scale_x_continuous(breaks = 1:6,
labels = c("Art", "Basic", "Comp", "Day", "Est", "Fin"))
Depending on what you're plotting, you may not even have to do this. For example, if your data was:
df <- data.frame(x = c("Art", "Basic", "Comp", "Day", "Est", "Fin"),
y = c(5, 2, 3, 4, 6, 1))
Then you could do, for example:
ggplot(df, aes(x, y)) + geom_col()
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 | Allan Cameron |


