Back
I am having the following dataframe:
ID Mean Min MaxA 10 4 18B 20 6 22C 12 2 78
ID Mean Min Max
A 10 4 18
B 20 6 22
C 12 2 78
From that, I want to plot a bar plot with ID on the x-axis where on each ID there will be bars with mean min and max. How can I do that?
I think the following code will work for you:
library(tidyverse)dat %>% # data from wide to long format gather(variable, value, -ID) %>% ggplot(aes(x = ID, y = value, fill = reorder(variable, value))) + geom_bar(stat = 'identity', position = 'dodge')
library(tidyverse)
dat %>%
# data from wide to long format
gather(variable, value, -ID) %>%
ggplot(aes(x = ID, y = value, fill = reorder(variable, value))) +
geom_bar(stat = 'identity', position = 'dodge')
With data:
dat <- read.table(text =" ID Mean Min MaxA 10 4 18B 20 6 22C 12 2 78", header = T)
dat <- read.table(text =" ID Mean Min Max
C 12 2 78", header = T)
If you want to know more about R then do check out the R programming course that will help you out in learning R from scratch.
31k questions
32.8k answers
501 comments
693 users