Merging two datasets to create a two axis chart

Dear all,
I'm working with two datasets in Rstudio, one have a Date time format DD/MM/YYYY HH:SS and the other only the Date format DD/MM/YYYY, I need to merge these datasets to create a chart with the date as X axis and one Y axis for one series and the other Y axis to the other series.
Can you let me know how can I do this?
I have create tow different charts:

install.packages(tidyverse)
install.packages(janitor)
install.packages("readxl")
install.packages("rpivotTable")
install.packages("plotly")
# Cargar los paquetes instalados
library(tidyverse)
library(janitor)
library(readxl)
library(rpivotTable)
library(dplyr)
library(plotly)
# Mostrar los archivos en el WD
list.files(path = "V://2022//Defectos//", pattern = ".xlsx$",recursive = TRUE)

# Cargar las bases de datos
Clima <- read_excel("V://2022//Defectos//Clima//Estacion_CDCUAUHTEMOC.xlsx")
glimpse(Clima)
# Graficar la humedad relativa
Grafica_Clima<-qplot(`Fecha Local`, `Humedad relativa (%)`, geom=c("smooth"),data = Clima)
ggplotly(Grafica_Clima)
# Cargar las bases de datos
Rechazos <- read_excel("V://2022//Defectos//Rechazo.xlsx")
glimpse(Rechazos)

# Graficar los defectos

Rechazos_MoldeQuebrado <- Rechazos[Rechazos$Causa == "DIMEN. BRUTO NC. CORAZON QUEBRADO", ]
unique(Rechazos_MoldeQuebrado)

Grafica_rechazos<-ggplot(Rechazos_MoldeQuebrado,aes(x = Fecha, y = Cantidad, )) +  
  geom_smooth()
ggplotly(Grafica_rechazos)

The information for the dataset named Clima is:

Fecha Local Dirección del Viento (grados) Dirección de ráfaga (grados) Rapidez de viento (km/h) Rapidez de ráfaga (km/h) Temperatura del Aire (°C) Humedad relativa (%) Presión Atmosférica (hpa) Precipitación (mm) Radiación Solar (W/m²)
13/07/2022 16:10 10 358 12.1 28.9 23.3 61 798.2 0 102
13/07/2022 16:00 42 62 15.7 25.5 24.4 56 798.1 0 139
13/07/2022 15:50 90 118 24.5 41.1 27.5 41 797.9 0 202
13/07/2022 15:40 107 129 24.4 38.5 28.2 38 797.9 0 390

The information for the dataset named Rechazos is:

Fecha Código Artículo Causa Cantidad Peso (kg)
miércoles, febrero 28, 2018 002784BR00 XD 351-H COL SHOT. METAL PROJ 1 0.089
martes, mayo 29, 2018 002784BR00 XD 351-H COL SHOT. METAL PROJ 1 0.089

I hope you can work with these images, I couldn't upload the files.

Thank you very much.

Hi, we don't have your files. Can you provide a reproducible example so we can see what they look like?

A handy way to supply some sample data is the dput() function. In the case of a large dataset something like dput(head(mydata, 100)) should supply the data we need.

Hola Sergio,

The others are right – it would help to have a reprex. Regardless, it seems you have a few different problems:

  1. Dates are in different formats
  2. Merging the datasets
  3. Plotting different 'facets' of the data.

Here are some resources to solve each:

  1. lubridate package, for working with dates: https://lubridate.tidyverse.org/
  2. joins in dplyr, to merge your data: Mutating joins — mutate-joins • dplyr
  3. facet wrapping in ggplot2: 17 Faceting | ggplot2

Best,
Tom

Thank you very much,
I'm looking the way to organize the information.
I'm new into R so I was trying to do it as a pivot table with two "Y" axis in Excel.
Thank you very much.
End have a nice day

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.