I want to make a boxplot as follows: on the x axis: the different groups (Healthy, Disease1, Disease2) on the y axis: the brain size , showing 'left brain size' and 'right brain size' side by side in different colors
I am using the ggplot function
data <- df[c("Group", "Left brain size", "Right brain size")]
ggplot(data, aes(x=Group ,y=..))+
geom_boxplot()
How should I organize my data to have : x = Group , y = brain size , fill = side ?
Thank you! PS: An example of my data is in the following table
Group | Left brain size | Right brain size |
---|---|---|
Healthy | 0.5 | 0.9 |
Healthy | 0.4 | 0.8 |
Healthy | 0.8 | 0.4 |
Disease 1 | 0.7 | 0.5 |
Disease 1 | 0.9 | 0.3 |
Disease 1 | 0.2 | 0.1 |
Disease 2 | 0.3 | 0.8 |
Disease 2 | 0.4 | 0.54 |
Disease 2 | 0.1 | 0.4 |
Disease 2 | 0.3 | 0.2 |
tidyr::pivot_longer()
. It shoul look like:tidyr::pivot_longer(df, cols = c("Left brain size", "Right brain size"), names_to = "side", values_to = "size")
– Paulggplot(data = df, aes(x = Group, y = size, fill = side)) + geom_...
. – Paul