0

I succeed to do this 2 ggplot graph.

The points of the graph on the right are datas who refere to the points of the curve on the left. SO this will be really great to combine this graph.

The y axes are the same, and x is just time convert to a numeric vector.

Do you know how can i do?

two ggplots

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"))

Code:

first<- ggplot( X, aes(x=date.mâle.graph, y=Cumulatif.mâle))+ geom_point()+ geom_line(size=1)+ggtitle("Floraison mâle en fonction du temps et de leurs ASIi") + xlab("Floraison mâle") + ylab("Individus de la variété")+ theme_minimal()+theme(
  plot.title = element_text(color="black", size=14, face="plain"),
  axis.title.x = element_text(color="black", size=16, face="plain"),
  axis.title.y = element_text(color="black", size=16, face="plain"),
  axis.text.x = element_text(face="bold", color="#993333", size=14, angle=0),
  axis.text.y = element_text(face="bold", color="#993333", size=14, angle=0))


second<- ggplot( X, aes(x=ASIi.floraisons.mâles, y=Cumulatif.mâle))+ geom_point(shape=20, color="blue", size=4 )+ theme_minimal()


plot_grid(first, second)
Rui Barradas
  • 70,273
  • 8
  • 34
  • 66
  • 1
    Can you post the code you've tried and sample data? Please edit **the question** with the code you ran and the output of `dput(df)`. Or, if it is too big with the output of `dput(head(df, 20))`. (Note: `df` is a placeholder for your dataset.) – Rui Barradas May 29 '21 at 06:40
  • yes of course sorry – Jean Mergnat May 29 '21 at 06:51
  • As you have already combined your graphs: Could you please clarify what's exactly the issue? – stefan May 29 '21 at 09:37
  • I would like only 1 graph, here there is two graph and the axe x (time ) is not clear at all. I hope there is a way to combine this 2 graphs in just one. – Jean Mergnat May 29 '21 at 13:49

1 Answers1

0

This sort of problem is usually a data reformating problem. See reshaping data.frame from wide to long format.
First, reformat X to X2, then plot the points, then plot the line subsetting the data.
Note also that the theme was simplified, if both axis.title.x and axis.title.y are to be set to the same values, set only the more general axis.title. And the same for axis.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)#,
  )
Rui Barradas
  • 70,273
  • 8
  • 34
  • 66