英文:
plot columns along multiple axes in R
问题
我尝试复制下面图片中的图表:
所有数据都在这个文件中:https://drive.google.com/file/d/1PbxTrX2NekN4i-2REInKcROdVnxX1xJr/view?usp=sharing
数据看起来是这样的:
我没有走得太远。我知道我只需要使用 geom_col()
,但如何获得每个月每十年一个图,都像图片中那样排列呢?我找不到相似的示例。
ggplot(
data=sealeveldecade,aes(x=month)) + #
geom_col(show.legend = FALSE) +
geom_col(aes(y = mediansealevelmonth))+
geom_col(aes(y = minsealevelmonth))+
labs(x = "月份", y = "由于RH2000的海平面(厘米)",title = "1960年-2009年每月的海平面中位数和最大值", subtitle = "每天每24小时的测量数据")
英文:
I am trying to replicate the plot as in the image below:
All data is in this file: https://drive.google.com/file/d/1PbxTrX2NekN4i-2REInKcROdVnxX1xJr/view?usp=sharing
data looks like this:
I didn't get far at all. I know i will just geom_col()
, but how do i get one plot per month per decade, all arranged like in the image? I can't find an example that looks alike neither.
ggplot(
data=sealeveldecade,aes(x=month)) + #
geom_col(show.legend = FALSE) +
geom_col(aes(y = mediansealevelmonth))+
geom_col(aes(y = minsealevelmonth))+
labs(x = "Month", y = "Sea level (cm) due to RH2000",title = "Median and maximum sea level per month during 1960−2009", subtitle = "Based on measurements every 24 hour per day")
答案1
得分: 1
您可以使用您的decades
变量创建分面:
已编辑以按月份顺序排列
library(dplyr)
library(ggplot2)
df %>%
mutate(month = factor(month, levels = month.abb)) %>%
arrange(month) %>%
ggplot(aes(month)) +
geom_col(aes(y = mediansealevelmonth), fill = 'red') +
geom_col(aes(y = minsealevelmonth), width = 0.6) +
facet_wrap(~decades, ncol = 1) +
labs(x = "月份", y = "由于RH2000而导致的海平面(厘米)", title = "1960年至2009年每月的中位数和最大海平面",
subtitle = "基于每天每24小时的测量")
创建于2023年3月31日,使用reprex v2.0.2
英文:
You can create facets with your decades
variables:
Edited to arrange months chronologically
library(dplyr)
library(ggplot2)
df %>%
mutate(month = factor(month, levels = month.abb)) %>%
arrange(month) %>%
ggplot(aes(month)) +
geom_col(aes(y = mediansealevelmonth), fill = 'red') +
geom_col(aes(y = minsealevelmonth), width = 0.6) +
facet_wrap(~decades, ncol = 1) +
labs(x = "Month", y = "Sea level (cm) due to RH2000",title = "Median and maximum sea level per month during 1960−2009", subtitle = "Based on measurements every 24 hour per day")
<!-- -->
<sup>Created on 2023-03-31 with reprex v2.0.2</sup>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论