0

I would like to join 2 charts with different color in one picture. Currently, I only can make them in separate pictures. Here is my data data 1 and data 2

and here is my script

#data 1
data <- read.csv("data1.csv", header=T)

library(tidyverse)
library(ggplot2)

data %>%
  mutate(row = row_number()) %>%
  pivot_longer(cols = -row, values_drop_na = TRUE) %>%
  ggplot(aes(value)) + aes(row, value, color=name)  +
  geom_jitter()+ geom_hline(yintercept=1.4,linetype="dashed") + ylab("Log") + xlab("") + 
  theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(), 
        panel.background = element_blank(), axis.line = element_line(colour = "black")) +  scale_color_manual(values = "purple") +
  theme(axis.ticks.x = element_blank(),axis.text.x = element_blank()) + theme(legend.title=element_blank()) +
  ggtitle("") + theme(axis.title.x = element_text(size = 15)) + 
  theme(axis.title.y = element_text(size = 15)) + 
  annotate(geom = "rect", xmin = 60, xmax = 300, 
           ymin = -Inf, ymax = Inf,
           color = "#D5D8DC", 
           fill = "#D5D8DC", alpha = 0.4
  )

#data 2
data <- read.csv("data2.csv", header=T)

library(tidyverse)
library(ggplot2)

data %>%
  mutate(row = row_number()) %>%
  pivot_longer(cols = -row, values_drop_na = TRUE) %>%
  ggplot(aes(value)) + aes(row, value, color=name)  +
  geom_jitter()+ geom_hline(yintercept=1.4,linetype="dashed") + ylab("Log") + xlab("") + 
  theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(), 
        panel.background = element_blank(), axis.line = element_line(colour = "black")) +  scale_color_manual(values = "purple") +
  theme(axis.ticks.x = element_blank(),axis.text.x = element_blank()) + theme(legend.title=element_blank()) +
  ggtitle("") + theme(axis.title.x = element_text(size = 15)) + 
  theme(axis.title.y = element_text(size = 15)) + 
  annotate(geom = "rect", xmin = 60, xmax = 300, 
           ymin = -Inf, ymax = Inf,
           color = "#D5D8DC", 
           fill = "#D5D8DC", alpha = 0.4
  )

Does anyone know how to join 2 charts in one picture?

Please help me.

I appreciate your kindness

Phil
  • 5,491
  • 3
  • 26
  • 61
Rigardus
  • 13
  • 1
  • 2
    You're not indicating how you want those two charts combined, but you can put them side by side using the `patchwork` package: https://patchwork.data-imaginist.com/ – Phil Nov 07 '21 at 16:46

0 Answers0