如何在一张图片中分为两个小号?
这是我的代码:
p14 <- ggplot(plot14, aes(x = Harvest, y = Percentage, fill = factor(Plant, level = orderplants)))+
geom_col(show.legend = FALSE)+
geom_vline(xintercept=3.5)+
labs(y = "Bedekking %",
x = NULL,
fill = "Plantensoort")+
theme_classic()
代码是关于植物的覆盖范围(我有70地块总共)。因此, bedekking 是荷兰语的覆盖范围。问题:数字代表测量的时间段:
- 2020年8月
- 2020年10
- 月2020年5月2021年
- 5月2021年
- 6月2021年
- 7月2021年
- 8月2021年
- 10月2021年10月
,我希望每个月的酒吧排队,所以会有两行(2020年和2021)相同月份的条形在彼此之上/下方(请参见下面的丑陋草图)。这是可以编码的,还是我需要更改整个数据集?
This is my code:
p14 <- ggplot(plot14, aes(x = Harvest, y = Percentage, fill = factor(Plant, level = orderplants)))+
geom_col(show.legend = FALSE)+
geom_vline(xintercept=3.5)+
labs(y = "Bedekking %",
x = NULL,
fill = "Plantensoort")+
theme_classic()
The code is about plant coverage of a plot (I have 70 plots in total). So bedekking is the Dutch word for coverage. The problem: the numbers represent the time periods of the measurements:
- July 2020
- August 2020
- October 2020
- May 2021
- June 2021
- July 2021
- August 2021
- October 2021
I would like the bars of each month to line up, so there would be two rows (2020 and 2021) where the bars of the same months are above/below each other (see ugly sketch below). Is this possible to code, or do I need to change my entire dataset?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您可以将一些示例原始数据作为可再现示例的一部分,那就更好了。我创建了一些构成的数据来说明。
理想情况下,您需要在编号的时间测量后面的原始日期,以便将日期分为几个月和几年作为单独的变量。假设您只有数字,则可以创建一些这样的逻辑来使几个月和几年。
您可以使用
facet_wrap
在相应的几个月中显示一年以上的一年。在2022-05-13上由 reprex软件包(v2.0.1)
It would be better if you could include some sample raw data as part of a reproducible example. I've created a little made up data to illustrate.
Ideally, you'd want the raw dates behind the numbered time measuements so that you can split the dates into months and years as separate variables. Assuming you only have the numbers, you could create some logic like this to make the months and years.
And you could use
facet_wrap
to show one year above another for the respective months.Created on 2022-05-13 by the reprex package (v2.0.1)