如何随着时间的推移绘制比较的直方图?

发布于 2025-02-05 01:00:53 字数 4362 浏览 2 评论 0原文

我需要长时间观察两种处理(WW和WS)下的叶子区域,所以我想随着时间的推移绘制直方图比较图表,但是我不知道如何将两个处理的两个栏放在一个中图形。

数据如下:

cd<-structure(list(Pos_heliaphen = c("Y12", "Y13", "Y20", "Y21", 
                                     "Y34", "Y35", "Y42", "Y43", "Z06", "Z07", "Z22", "Z23", "Z36", 
                                     "Z37", "Z44", "Z45", "Y12", "Y13", "Y20", "Y21", "Y34", "Y35", 
                                     "Y42", "Y43", "Z06", "Z07", "Z22", "Z23", "Z36", "Z37", "Z44", 
                                     "Z45"), traitement = c("WW", "WS", "WS", "WW", "WS", "WW", "WS", 
                                                            "WW", "WW", "WS", "WS", "WW", "WS", "WW", "WW", "WS", "WW", "WS", 
                                                            "WS", "WW", "WS", "WW", "WS", "WW", "WW", "WS", "WS", "WW", "WS", 
                                                            "WW", "WW", "WS"), Variete = c("Angelica", "Angelica", "Angelica", 
                                                                                           "Angelica", "Angelica", "Angelica", "Angelica", "Angelica", "Angelica", 
                                                                                           "Angelica", "Angelica", "Angelica", "Angelica", "Angelica", "Angelica", 
                                                                                           "Angelica", "Angelica", "Angelica", "Angelica", "Angelica", "Angelica", 
                                                                                           "Angelica", "Angelica", "Angelica", "Angelica", "Angelica", "Angelica", 
                                                                                           "Angelica", "Angelica", "Angelica", "Angelica", "Angelica"), 
                   Date_obs = structure(c(19135, 19135, 19135, 19135, 19135, 
                                          19135, 19135, 19135, 19135, 19135, 19135, 19135, 19135, 19135, 
                                          19135, 19135, 19145, 19145, 19145, 19145, 19145, 19145, 19145, 
                                          19145, 19145, 19145, 19145, 19145, 19145, 19145, 19145, 19145
                   ), class = "Date"), SF_Plante_Totale = c(0, 0, 0, 0, 0, 0, 
                                                            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 67589.64, 71868.33, 69883.2, 
                                                            73892.79, 72106.38, 82228.68, 73393.92, 63867.78, 70127.46, 
                                                            64710.27, 76991.58, 75486.69, 80237.34, 74250.9, 68804.73, 
                                                            63714.6)), row.names = c(NA, -32L), class = c("tbl_df", "tbl", 
                                                                                                          "data.frame"))

我使用的代码如下(有冗余操作,因为我的原始数据具有更多的“ VELIETE”):

df<-subset(cd, Variete %in% c("Angelica"))
options(scipen=200)
df$Date_obs <- as.Date(df$Date_obs)



df %>% 
  select(1,2,3,4,5) %>% 
  pivot_longer(starts_with("SF")) %>% 
  ggplot(aes(Date_obs, value,group=Pos_heliaphen)) +
  geom_bar(stat = "identity",fill="steelblue") +
  scale_x_date(date_labels = "%Y-%m-%d")+
  facet_wrap(~Pos_heliaphen,drop=TRUE)+
  labs(y=expression(paste('Original total leaf area (mm'^2,')')))+
  theme(legend.position="bottom", axis.text.x = element_text(angle = 90, hjust = 1), axis.title.x = element_blank())

我得到了以下数字:

net/5mz5b.jpg“ rel =“ nofollow noreferrer 两个条形在一个图中圆圈(一个是WW,另一个是WS)。 像下面的图。然后只剩下8个图。

因为现在只是观察的开始,所以我们实际上没有时间表。但是下面的两个数字来自去年。我只是不知道如何将同一天的WS和WW放在一个数字中。

I need to observe the leaf area under the two treatments (WW and WS) for a long time, so I want to draw a histogram comparison chart over time, but I don't know how to put the two bars of two treatments in one graph.

The data is as follows:

cd<-structure(list(Pos_heliaphen = c("Y12", "Y13", "Y20", "Y21", 
                                     "Y34", "Y35", "Y42", "Y43", "Z06", "Z07", "Z22", "Z23", "Z36", 
                                     "Z37", "Z44", "Z45", "Y12", "Y13", "Y20", "Y21", "Y34", "Y35", 
                                     "Y42", "Y43", "Z06", "Z07", "Z22", "Z23", "Z36", "Z37", "Z44", 
                                     "Z45"), traitement = c("WW", "WS", "WS", "WW", "WS", "WW", "WS", 
                                                            "WW", "WW", "WS", "WS", "WW", "WS", "WW", "WW", "WS", "WW", "WS", 
                                                            "WS", "WW", "WS", "WW", "WS", "WW", "WW", "WS", "WS", "WW", "WS", 
                                                            "WW", "WW", "WS"), Variete = c("Angelica", "Angelica", "Angelica", 
                                                                                           "Angelica", "Angelica", "Angelica", "Angelica", "Angelica", "Angelica", 
                                                                                           "Angelica", "Angelica", "Angelica", "Angelica", "Angelica", "Angelica", 
                                                                                           "Angelica", "Angelica", "Angelica", "Angelica", "Angelica", "Angelica", 
                                                                                           "Angelica", "Angelica", "Angelica", "Angelica", "Angelica", "Angelica", 
                                                                                           "Angelica", "Angelica", "Angelica", "Angelica", "Angelica"), 
                   Date_obs = structure(c(19135, 19135, 19135, 19135, 19135, 
                                          19135, 19135, 19135, 19135, 19135, 19135, 19135, 19135, 19135, 
                                          19135, 19135, 19145, 19145, 19145, 19145, 19145, 19145, 19145, 
                                          19145, 19145, 19145, 19145, 19145, 19145, 19145, 19145, 19145
                   ), class = "Date"), SF_Plante_Totale = c(0, 0, 0, 0, 0, 0, 
                                                            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 67589.64, 71868.33, 69883.2, 
                                                            73892.79, 72106.38, 82228.68, 73393.92, 63867.78, 70127.46, 
                                                            64710.27, 76991.58, 75486.69, 80237.34, 74250.9, 68804.73, 
                                                            63714.6)), row.names = c(NA, -32L), class = c("tbl_df", "tbl", 
                                                                                                          "data.frame"))

The code I used is as follows (There are redundant operations because my original data has more "variete"):

df<-subset(cd, Variete %in% c("Angelica"))
options(scipen=200)
df$Date_obs <- as.Date(df$Date_obs)



df %>% 
  select(1,2,3,4,5) %>% 
  pivot_longer(starts_with("SF")) %>% 
  ggplot(aes(Date_obs, value,group=Pos_heliaphen)) +
  geom_bar(stat = "identity",fill="steelblue") +
  scale_x_date(date_labels = "%Y-%m-%d")+
  facet_wrap(~Pos_heliaphen,drop=TRUE)+
  labs(y=expression(paste('Original total leaf area (mm'^2,')')))+
  theme(legend.position="bottom", axis.text.x = element_text(angle = 90, hjust = 1), axis.title.x = element_blank())

And I got the figure as below:

enter image description here

But I want to compare the two bars circled together in one graph (One is WW, the other is WS).
Like this graph below. Then only 8 graphs left in the end.

enter image description here

Because right now is just the beginning of observation, so we don't really have time line. But the two figures below are from last year. I just don't know How to put the WS and WW of the same day in one figure.
enter image description here
enter image description here
enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南笙 2025-02-12 01:00:53

我不确定这就是您想要的,但是

df %>% 
  select(1,2,3,4,5) %>% 
  pivot_longer(starts_with("SF")) %>%
  mutate(w = substr(Pos_heliaphen, start = 1, stop = 2)) %>%
  ggplot(aes(Date_obs, value,group=traitement, fill = traitement)) +
  geom_bar(stat = "identity", position = "dodge") +
  scale_x_date(date_labels = "%Y-%m-%d")+
  facet_wrap(~w,drop=TRUE)+
  labs(y=expression(paste('Original total leaf area (mm'^2,')')))+
  theme(legend.position="bottom", axis.text.x = element_text(angle = 90, hjust = 1), axis.title.x = element_blank())

”在此处输入图像说明“

new

df %>% 
  select(1,2,3,4,5) %>% 
  pivot_longer(starts_with("SF")) %>%
  mutate(w = substr(Pos_heliaphen, start = 1, stop = 2)) %>%
  group_by(Date_obs, w) %>%
  filter(!(sum(value) == 0)) %>%
  ggplot(aes(Date_obs, value,group=traitement, fill = traitement)) +
  geom_bar(stat = "identity", position = "dodge") +
  geom_text(aes(label = Pos_heliaphen), position=position_dodge(width=0.9), size = 2, vjust = -0.5) +
  ylim(c(0, 90000)) +
  scale_x_date(date_labels = "%Y-%m-%d")+
  facet_wrap(~w,drop=TRUE)+
  labs(y=expression(paste('Original total leaf area (mm'^2,')')))+
  theme(legend.position="bottom", axis.text.x = element_text(angle = 45, hjust = 1), axis.title.x = element_blank()) + 
  theme(
    strip.background = element_blank(),
    strip.text.x = element_blank()
  ) +
  labs(title = "Angelica")

“在此处输入图像说明”

添加

df<-subset(dff, Variete %in% c("Angelica"))
options(scipen=200)
df$Date_obs <- as.Date(df$Date_obs)
  
df <- df %>% 
  select(1,2,3,4,5) %>% 
  pivot_longer(starts_with("SF")) %>%
  mutate(w = substr(Pos_heliaphen, start = 1, stop = 2))
df2 <- df %>%
  group_by(w, Date_obs) %>%
  summarize(ww = paste0(Pos_heliaphen, collapse = "-"))
df %>%
  left_join(df2, by = c("w", "Date_obs")) %>%
  ggplot(aes(Date_obs, value,group=traitement, fill = traitement)) +
  geom_bar(stat = "identity", position = "dodge") +
  ylim(c(0, 90000)) +
  scale_x_date(date_labels = "%Y-%m-%d")+
  #xlim(c(as.Date("2022-05-23"), as.Date("2020-06-02"))) +
  facet_wrap(~ww,drop=TRUE)+
  labs(y=expression(paste('Original total leaf area (mm'^2,')')))+
  theme(legend.position="bottom", axis.text.x = element_text(angle = 45, hjust = 1), axis.title.x = element_blank()) + 

  labs(title = "Angelica")

I'm not sure this is what you wanted but

df %>% 
  select(1,2,3,4,5) %>% 
  pivot_longer(starts_with("SF")) %>%
  mutate(w = substr(Pos_heliaphen, start = 1, stop = 2)) %>%
  ggplot(aes(Date_obs, value,group=traitement, fill = traitement)) +
  geom_bar(stat = "identity", position = "dodge") +
  scale_x_date(date_labels = "%Y-%m-%d")+
  facet_wrap(~w,drop=TRUE)+
  labs(y=expression(paste('Original total leaf area (mm'^2,')')))+
  theme(legend.position="bottom", axis.text.x = element_text(angle = 90, hjust = 1), axis.title.x = element_blank())

enter image description here

New

df %>% 
  select(1,2,3,4,5) %>% 
  pivot_longer(starts_with("SF")) %>%
  mutate(w = substr(Pos_heliaphen, start = 1, stop = 2)) %>%
  group_by(Date_obs, w) %>%
  filter(!(sum(value) == 0)) %>%
  ggplot(aes(Date_obs, value,group=traitement, fill = traitement)) +
  geom_bar(stat = "identity", position = "dodge") +
  geom_text(aes(label = Pos_heliaphen), position=position_dodge(width=0.9), size = 2, vjust = -0.5) +
  ylim(c(0, 90000)) +
  scale_x_date(date_labels = "%Y-%m-%d")+
  facet_wrap(~w,drop=TRUE)+
  labs(y=expression(paste('Original total leaf area (mm'^2,')')))+
  theme(legend.position="bottom", axis.text.x = element_text(angle = 45, hjust = 1), axis.title.x = element_blank()) + 
  theme(
    strip.background = element_blank(),
    strip.text.x = element_blank()
  ) +
  labs(title = "Angelica")

enter image description here

add

df<-subset(dff, Variete %in% c("Angelica"))
options(scipen=200)
df$Date_obs <- as.Date(df$Date_obs)
  
df <- df %>% 
  select(1,2,3,4,5) %>% 
  pivot_longer(starts_with("SF")) %>%
  mutate(w = substr(Pos_heliaphen, start = 1, stop = 2))
df2 <- df %>%
  group_by(w, Date_obs) %>%
  summarize(ww = paste0(Pos_heliaphen, collapse = "-"))
df %>%
  left_join(df2, by = c("w", "Date_obs")) %>%
  ggplot(aes(Date_obs, value,group=traitement, fill = traitement)) +
  geom_bar(stat = "identity", position = "dodge") +
  ylim(c(0, 90000)) +
  scale_x_date(date_labels = "%Y-%m-%d")+
  #xlim(c(as.Date("2022-05-23"), as.Date("2020-06-02"))) +
  facet_wrap(~ww,drop=TRUE)+
  labs(y=expression(paste('Original total leaf area (mm'^2,')')))+
  theme(legend.position="bottom", axis.text.x = element_text(angle = 45, hjust = 1), axis.title.x = element_blank()) + 

  labs(title = "Angelica")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文