[英]Shiny/R: Too many factors on line graph
I'm using ggplot2 and shiny to create a graph, however there are too many factors appearing on the x axis. 我正在使用ggplot2和Shiny来创建图形,但是x轴上出现了太多因素。
output$housePlot <- renderPlot({
ggplot(data=houseratio, aes(x=Year, y=Ratio, group=Region, colour=Region)) +
geom_line() +
geom_point()
})
I've tried reading this post but I can't get the seq() right. 我试图阅读这篇文章,但我无法正确使用seq()。 My data is in long format, looks like this: 我的数据采用长格式,如下所示:
Year Ratio Region
1983 Q1 2.9 Northern
1983 Q2 3 Northern
1983 Q3 3.1 Northern
1983 Q4 3 Northern
...
2015 Q2 5.1 UK
2015 Q3 5.1 UK
2015 Q4 5.2 UK
2016 Q1 5.2 UK
Using this code: 使用此代码:
output$housePlot <- renderPlot({
ggplot(data=houseratio, aes(x=Year, y=Ratio, group=Region, colour=Region)) +
scale_x_discrete(breaks = seq(1, 1864, by = 4)) +
geom_line() +
geom_point()
})
All the factors disappear! 所有因素都消失了!
I only need each year showing, not individual quarters. 我只需要每年显示,而不需要个别季度。 Any suggestions? 有什么建议么?
(Thanks) (谢谢)
The fastest route is ultimately to make 'Year' a numeric type. 最快的方法最终是使“年”成为数字类型。 This requires a few conversions: 这需要进行一些转换:
library("zoo")
library("dplyr")
houseratio <- houseratio %>% mutate(Year = Year %>% as.character() %>%
as.yearqtr() %>% as.numeric())
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.