Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in R Programming by (50.2k points)

I am having the following dataframe:

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?

1 Answer

0 votes
by (107k points)

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')

With data:

dat <- read.table(text =" ID  Mean Min Max

A   10    4   18

B   20    6   22

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

Browse Categories

...