-1

The problem is to have two charts based on different columns in one chart

How chart should look like

example data

set.seed(42) 
data <- data.frame(Id=1:20, 
Q_3_1=sample(1:6, 20, replace=TRUE), 
Q_3_2=sample(1:6, 20, replace=TRUE), 
Level=sample(c("AAAA", "BBBB", "CCCC", "DDDD"), 20, replace=TRUE))
Perlak99
  • 13
  • 2
  • 1
    It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input that can be used to test and verify possible solutions. Do not post data as images. We cannot copy/paste that into R for testing. Show your attempts so far and make it clear where you are getting stuck. – MrFlick Sep 02 '21 at 22:46

1 Answers1

0

If I understood correctly, here is a tidyverse solution:

Libraries

library(tidyverse)

Data

set.seed(42) 
data <- data.frame(Id=1:20, 
                   Q_3_1=sample(1:6, 20, replace=TRUE), 
                   Q_3_2=sample(1:6, 20, replace=TRUE), 
                   Level=sample(c("AAAA", "BBBB", "CCCC", "DDDD"), 20, replace=TRUE))

Plot code

data %>% 
   #Pivot data to create a single column with all values from Q_3_1 to Q_3_2
   pivot_longer(cols = Q_3_1:Q_3_2) %>% 
   ggplot(aes(name,value, fill = Level))+
   geom_boxplot()

Output

enter image description here

Vinícius Félix
  • 8,448
  • 6
  • 16
  • 32