我很難在ggplot2盒圖上繪製Y軸上的時間。作爲ggplot2中的y軸標籤的時間
任何想法如何以時間呈現我的y軸?
目前,我的Y軸是數字,日期標籤適用於該系列。
我寧願展會時間:而不是顯示所有的數據在Y軸(HH MM),標籤
我的數據:
structure(list(Date = structure(c(17511, 17512, 17513, 17514, 17515), class = "Date"),
T.min = c(1513584134, 1513580301, 1513582918, 1513583058, 1513584465),
T.mean = c(1513585975.14286, 1513584408.14286, 1513584580.57143, 1513583202.2, 1513585681),
T.max = c(1513587691, 1513587419, 1513585508, 1513583516, 1513587100),
min_labels = c("08:02", "06:58", "07:41", "07:44", "08:07"),
mean_labels = c("08:32", "08:06", "08:09", "07:46", "08:28"),
max_labels = c("09:01", "08:56", "08:25", "07:51", "08:51")), .Names = c("Date", "T.min", "T.mean", "T.max", "min_labels", "mean_labels", "max_labels"), row.names = c(NA, -5L), class = "data.frame")
我的陰謀(y軸和繪製的值是POSIXct格式):
#Library
library(ggplot2)
library(scales)
#Plot
theme_set(theme_bw())
ggplot(df, aes(x = Date)) +
geom_boxplot(aes(ymin = T.min, lower = T.min, middle = T.mean, upper = T.max, ymax = T.max),
stat = "identity", fill = "antiquewhite", color = "black") +
geom_line(aes(x=Date, y=T.mean),color='firebrick2', size=3, show.legend = FALSE) +
xlab('Shift Start Date') +
ylab('Time') +
coord_cartesian(ylim =c(Y.min, Y.max)) +
scale_x_date(date_labels = "%d-%b", breaks = pretty_breaks(5)) +
theme(axis.text=element_text(size=15), axis.title=element_text(size=15,face="bold")) +
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
theme(axis.text.y = element_blank()) +
geom_text(aes(x=Date, y = T.min, label = min_labels), size=5, vjust=1.5, check_overlap=TRUE) +
geom_text(aes(x=Date, y = T.mean, label = mean_labels), size=5, vjust=-0.5, check_overlap=TRUE) +
geom_text(aes(x=Date, y = T.max, label = max_labels), size=5, vjust=-1.5, check_overlap=TRUE) +
theme(axis.text=element_text(size=15), axis.title=element_text(size=15,face="bold")) +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
是我的目標對於(在MS Paint中添加標籤並且與數據不匹配,但您可以看到我想要的內容):-)
y軸應該怎麼樣? – Jimbou
能否請您解釋一下:「隱藏Y軸標籤....顯示y軸標籤並隱藏最小和最大數據標籤」 – PoGibas
感謝您提出的問題,我編輯的帖子更加清晰。非常感謝! – Jernau