-1
我有日期從05/10/2017, 05/11/2017, ...08/04/2017...
顯示日期清晰現在在哪裏的文字重疊
我試圖ggplot在x軸和y軸的另一列將日期的列。下面是我使用的代碼:
dataframe %>% ggplot(aes(x = date, y = sum)) +
geom_point()
如何讓我的日期更清晰?我應該縮短日期還是改變ggplot2中的內容?
我有日期從05/10/2017, 05/11/2017, ...08/04/2017...
顯示日期清晰現在在哪裏的文字重疊
我試圖ggplot在x軸和y軸的另一列將日期的列。下面是我使用的代碼:
dataframe %>% ggplot(aes(x = date, y = sum)) +
geom_point()
如何讓我的日期更清晰?我應該縮短日期還是改變ggplot2中的內容?
下面是一個簡單的例子,它使用它們表示的變量類型。 (隨意發生相應的變化,例如:variable
== sum
你的情況)
library(ggplot2)
library(dplyr)
df1 <- data.frame(dates = 1:5,Variable = rnorm(mean = 0.5,5))
df2 <- data.frame(dates = 1:5,Variable = rnorm(mean = -0.5,5))
df3 <- df1 %>%
mutate(Type = 'a') %>%
bind_rows(df2 %>%
mutate(Type = 'b'))
ggplot(df3,aes(y = Variable,x = dates,color = Type)) +
geom_line()
您可以添加:
+ theme(axis.text.x = element_text(angle = 90))
請參閱[MCVE。 –
確保日期實際上是日期,而不是字符串/因素。但是請按照上面的建議嘗試創建一個小數據示例。 – user20650
https://stackoverflow.com/questions/11748384/formatting-dates-on-x-axis-in-ggplot2/11748820#11748820 – user20650