我有一个大约108m行数据的数据框,分为7列。我用这个R脚本来制作一个盒子图:使用ggplot2 log10刻度上的小勾号
ggplot(expanded_results, aes(factor(hour), dynamic_nox)) +
geom_boxplot(fill="#6699FF", outlier.size = 0.5, lwd=.1) +
scale_y_log10() +
stat_summary(fun.y=mean, geom="line", aes(group=1, colour="red")) +
ylab(expression(Exposure~to~NO[x])) +
xlab(expression(Hour~of~the~day)) +
ggtitle("Hourly exposure to NOx") +
theme(axis.text=element_text(size=12, colour="black"),
axis.title=element_text(size=12, colour="black"),
plot.title=element_text(size=12, colour="black"),
legend.position="none")
这张图看起来像这样。它非常好,但是最好有一个值朝向Y轴的顶部。我猜它应该是类似于1000的东西,因为Y轴是log10比例。我不知道如何做到这一点,虽然?
任何想法吗?
编辑:回复DrDom: 尝试添加scale_y_log10(breaks=c(0,10,100,1000))
。这样做的输出,是这样的:
做的输出如下: scale_y_log10(breaks=c(0,10,100,1000), limits=c(0,1000))
是一个错误:
Error in seq.default(dots[[1L]][[1L]], dots[[2L]][[1L]], length = dots[[3L]][[1L]]:
'from' cannot be NA, NaN or infinite
在respnonse到夏侯谁建议以下代码:
library(ggplot2)
library(scales)
ggplot(expanded_results, aes(factor(hour), dynamic_nox)) +
geom_boxplot(fill="#6699FF", outlier.size = 0.5, lwd=.1) +
stat_summary(fun.y=mean, geom="line", aes(group=1, colour="red")) +
scale_y_continuous(breaks=c(0,10,100,1000,3000), trans="log1p") +
labs(title="Hourly exposure to NOx", x=expression(Hour~of~the~day), y=expression(Exposure~to~NO[x])) +
theme(axis.text=element_text(size=12, colour="black"), axis.title=element_text(size=12, colour="black"),
plot.title=element_text(size=12, colour="black"), legend.position="none")
它生成此图。我做错了什么?我仍然错过了'1000'勾号标签?考虑到大部分数据是在哪里,10和100之间的勾号也会很好?
尝试添加'scale_y_log10(breaks = c(0,10,100,1000))'或'scale_y_log10(breaks = c(0,10,100,1000),limits = c(0,1000))' – DrDom
Hi DrDom。感谢您的建议。结果添加到我的帖子上面。请注意,数据看起来有点不同,因为再次运行图形创建需要大约20分钟,所以我只是使用了一部分数据用于演示目的。还不完全。 :-( – TheRealJimShady