How to superimpose bar plots in R?

前端 未结 2 466
被撕碎了的回忆
被撕碎了的回忆 2021-01-17 06:12

I\'m trying to create a figure similar to the one below (taken from Ro, Russell, & Lavie, 2001). In their graph, they are plotting bars for the errors (i.e., accuracy) w

2条回答
  •  感情败类
    2021-01-17 07:07

    It is pretty easy to make the bars in ggplot. Here is some example code. No two y-axes though (although look here for a way to do that too).

    library(ggplot2)
    data.1 <- sample(1000:2000, 10)
    data.2 <- sample(500:1000, 10)
    
    library(ggplot2)
    ggplot(mapping = aes(x, y)) +
      geom_bar(data = data.frame(x = 1:10, y = data.1), width = 0.8, stat = 'identity') +
      geom_bar(data = data.frame(x = 1:10, y = data.2), width = 0.4, stat = 'identity', fill = 'white') +
      theme_classic() + scale_y_continuous(expand = c(0, 0))
    

提交回复
热议问题