如何在X轴上设置数年作为GGPLOT R中的整数
我不知道为什么,但是当我运行GGPLOT堆叠的区域图表时,X轴的数年是像2012.5这样的双打。...我将它们设置为整数,但仍然存在这个问题。有解决方案吗?
df$Year <- as.integer(df$Year)
order <- df %>% filter(Year ==max(df$Year) ) %>% arrange(desc(Sales)) %>% select(Category)
df$Category <- factor(df$Category, levels = order$Category)
df %>%
ggplot(aes(x = Year, y = Sales, fill = Category)) +
geom_area()
I don't know why but when I run ggplot stacked area chart, years on the x-axis are doubles like 2012.5.... I set them as integer but still have this issue. Any solution?
df$Year <- as.integer(df$Year)
order <- df %>% filter(Year ==max(df$Year) ) %>% arrange(desc(Sales)) %>% select(Category)
df$Category <- factor(df$Category, levels = order$Category)
df %>%
ggplot(aes(x = Year, y = Sales, fill = Category)) +
geom_area()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以指定与
scale_x_continouul()
一起使用的休息时间。为了使其更具动态性并自动选择数据上的限制,请使用:
如果您不想显示每年,则可以使用
seq()
每年每年都有。例如每三年每三年:You can specify the breaks to use with
scale_x_continuous()
.To make it more dynamic and automatically choose the limits base on your data, use:
And if you don't want to show every year you can use
seq()
to just have every Nth year. E.g. for every third year:您可以添加
scale_x_continouul(breaks = seq(df $ egar),max(df $ ear),1))
per:在2022-04-30 (v2.0.1)
You could add
scale_x_continuous(breaks = seq(min(df$year), max(df$year), 1))
per below:Created on 2022-04-30 by the reprex package (v2.0.1)