Reproduce the plots in the ‘Methods’ part

  1. a dashed vertical line dividing two sets of rectangular bars.

    plot1.png

     library(ggplot2)
    
     # Install and load the ggplot2 package
     install.packages("ggplot2")
     library(ggplot2)
    
     # Create a mock dataset for the left visualization
     left_data <- data.frame(
       group = c(rep("A", 5), rep("B", 3)),
       value = c(1, 2, 3, 4, 5, 6, 7, 8)
     )
    
     left_plot <- ggplot(left_data, aes(x=group, y=value)) +
       geom_col(position="dodge") +
       geom_vline(xintercept=1.5, linetype="dashed") +
       theme_minimal()
    
     # Create a mock dataset for the right visualization
     right_data <- data.frame(
       x = 1:20,
       y = rnorm(20, 10, 5),
       group = sample(c("red", "blue"), 20, replace=TRUE)
     )
    
     right_plot <- ggplot(right_data, aes(x=x, y=y)) +
       geom_col(aes(fill="blue"), width=0.5) +
       geom_point(aes(color=group), size=4, position=position_jitter(width=0.3, height=0)) +
       scale_color_manual(values=c("red"="red", "blue"="blue")) +
       theme_minimal()
    
     # Combine and display the plots
     library(gridExtra)
     png("plot1.png", width=800, height=800)
     grid.arrange(left_plot, right_plot, ncol=2)
     dev.off()
  2. a bar plot with overlaid scatter points in two colors.

Leave a Reply

Your email address will not be published. Required fields are marked *