Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 如何组合2 ggplot图?_R_Ggplot2 - Fatal编程技术网

R 如何组合2 ggplot图?

R 如何组合2 ggplot图?,r,ggplot2,R,Ggplot2,我成功地绘制了这个2 ggplot图 右侧图表的点是指左侧曲线点的数据。所以这将是真正伟大的结合这个图表 y轴是相同的,x只是时间转换为数字向量 你知道我该怎么做吗 X <- structure(list(Varietes = c("Abelastone", "Abelastone", "Abelastone", "Abelastone", "Abelastone"), ligne.re

我成功地绘制了这个2 ggplot图

右侧图表的点是指左侧曲线点的数据。所以这将是真正伟大的结合这个图表

y轴是相同的,x只是时间转换为数字向量

你知道我该怎么做吗

X <- 
structure(list(Varietes = c("Abelastone", "Abelastone", "Abelastone", 
"Abelastone", "Abelastone"), ligne.rep = c(1, 1, 1, 1, 1), 
Pied = c(1, 3, 2, 6, 7), Date.floraison.mâle = c(7.29, 8.01, 8.02, 8.03, 
8.04), Date.floraison.femelle = structure(c(1628553600, 1628640000, 
1629158400, 1629849600, 1629158400), tzone = "UTC", class = c("POSIXct", 
"POSIXt")), ASIi = c(12, 10, 15, 22, 13), Hauteur.des.pieds = c(230, 
226, 228, 240, 233), Hauteur.des.soies = c(123, 116, 118, 124, 
122), Cumulatif.mâle = c(1, 2, 3, 4, 5), date.mâle.graph = c(29, 
32, 33, 34, 35), ASIi.floraisons.mâles = c(41, 42, 48, 56, 48
)), row.names = c(NA, -5L), na.action = structure(c(`6` = 6L, 
`10` = 10L, `20` = 20L, `21` = 21L, `24` = 24L), class = "omit"), 
class = c("tbl_df", "tbl", "data.frame"))


X这类问题通常是数据重新格式化问题。请参阅。
首先,将
X
重新格式化为
X2
,然后绘制点,然后绘制数据子集的线。
还请注意,
主题
被简化,如果
轴.title.x
轴.title.y
都要设置为相同的值,则只设置更通用的
轴.title
。对于轴.text
也是如此

library(dplyr)
library(tidyr)
library(ggplot2)

X %>%
  select(date.mâle.graph, ASIi.floraisons.mâles, Cumulatif.mâle) %>%
  pivot_longer(
    cols = c(date.mâle.graph, ASIi.floraisons.mâles),
  ) -> X2

ggplot(X2, aes(x = value, y = Cumulatif.mâle, color = name)) +
  geom_point()+
  geom_line(
    data = subset(X2, name == "date.mâle.graph"),
    inherit.aes = TRUE,
    size = 1
  ) +
  ggtitle("Floraison mâle en fonction du temps et de leurs ASIi") +
  xlab("Floraison mâle") +
  ylab("Individus de la variété") +
  xlim(range(pretty(X2$value))) +
  scale_color_manual(values = c("blue", "black")) +
  theme_minimal()+
  theme(
    plot.title = element_text(color="black", size=14, face="plain"),
    axis.title = element_text(color="black", size=16, face="plain"),
    axis.text = element_text(face="bold", color="#993333", size=14, angle=0)#,
  )

你能发布你尝试过的代码和样本数据吗?请使用您运行的代码和
dput(df)
的输出编辑问题。或者,如果dput(头部(df,20))的输出太大。(注意:
df
是您的数据集的占位符。)是的,当然抱歉,因为您已经组合了您的图表:请您澄清到底是什么问题吗?我只想要一个图表,这里有两个图表,斧头x(时间)一点也不清楚。我希望有一种方法可以把这两张图合并成一张。谢谢你们,你们帮了我这么多,祝你们过得愉快
library(dplyr)
library(tidyr)
library(ggplot2)

X %>%
  select(date.mâle.graph, ASIi.floraisons.mâles, Cumulatif.mâle) %>%
  pivot_longer(
    cols = c(date.mâle.graph, ASIi.floraisons.mâles),
  ) -> X2

ggplot(X2, aes(x = value, y = Cumulatif.mâle, color = name)) +
  geom_point()+
  geom_line(
    data = subset(X2, name == "date.mâle.graph"),
    inherit.aes = TRUE,
    size = 1
  ) +
  ggtitle("Floraison mâle en fonction du temps et de leurs ASIi") +
  xlab("Floraison mâle") +
  ylab("Individus de la variété") +
  xlim(range(pretty(X2$value))) +
  scale_color_manual(values = c("blue", "black")) +
  theme_minimal()+
  theme(
    plot.title = element_text(color="black", size=14, face="plain"),
    axis.title = element_text(color="black", size=16, face="plain"),
    axis.text = element_text(face="bold", color="#993333", size=14, angle=0)#,
  )