0
votes

I would really appreciate your help with this question

The dataframe below, 'df', generates a bar plot.

item number year a 400 2014 b 150 2015 c 300 2011 a 300 2015 c 400 2011 c 100 2011 b 250 2014

Complete the following code to generates the bar plot below

newdf <- df %>%

(number = number/100) %>% group_by(

) %>%

(m = median( ))

This is the bar plot

1

1 Answers

1
votes

Try this:

library(ggplot2)
library(dplyr)
#Code
df %>%
  mutate(number = number/100) %>%
  group_by(item)%>%
  summarise(m = median(number)) %>%
  ggplot(aes(x=item,y=m))+
  geom_bar(stat = 'identity')

Output:

enter image description here

Some data used:

#Data
df <- structure(list(item = c("a", "b", "c", "a", "c", "c", "b"), number = c(400L, 
150L, 300L, 300L, 400L, 100L, 250L), year = c(2014L, 2015L, 2011L, 
2015L, 2011L, 2011L, 2014L)), class = "data.frame", row.names = c(NA, 
-7L))