0
votes

I am trying to use plotly to make a bar chart using the following data:

enter image description here

Any help on this is appreciated.

I want it to look similar to this graph but instead of men and women it has the year or income as the legend enter image description here

Dataframe:

maleincomequalification <-read.csv("MaleIncomeQualification.csv")
femaleincomequalification <-read.csv("FemaleIncomeQualification.csv")

column names/variables:

 "Year"                                      
 "No.Qualification"                          
 "Lower.secondary.school.qualification"      
 "Upper.secondary.school.qualification"      
 "Level.1.3.post.school.certificate"         
 "Level.4.6.certificate.or.diploma"          
 "Bachelors.degree.and.level.7.qualification"
 "Postgraduate.qualification"

data.frame(Year = 2013:2019, 
                   No_Qualification = c(561,575,579, 627, 682, 674, 707), 
                   Lower_secondary_school_qualification = c(678, 690, 686, 759, 710, 770, 798), 
                   Upper_secondary_school_qualification = c(626, 605, 645, 688, 722, 761, 805), 
                   Level_1_3_post_school_certificate = c(631, 651, 657, 660, 672, 703, 762),
                   Level_4_6_certificate_or_diploma = c(753, 780, 763, 848, 844, 815, 863), 
                   Bachelors_degree = c(980,1006,1028, 1077, 1091, 1125, 1151), 
                   Postgraduate_qualification = c(1178, 1245, 1244, 1331, 1399, 1385, 1474))
1
Hello, have aa look at the plotly help site: plot.ly/r/bar-charts. There is an example for your question.Florian
I had a look on this but I don't understand how to use it for my dataRaisham
Ok, then would you please provide a reproducible example and provide your data (e.g. as a dataframe or tibble)Florian
i've provided the dataframe and the columns from the datasetRaisham
Please provide a dataframe which other users can copy/paste. E.g.: data.frame(Year = 2013:2015, No_Qualification = c(561,575,579), Bachelors_degree = c(c(980,1006,1028)))Florian

1 Answers

0
votes

Here is one solution:

data <- data.frame(Year = 2013:2019, 
                   No_Qualification = c(561,575,579, 627, 682, 674, 707), 
                   Lower_secondary_school_qualification = c(678, 690, 686, 759, 710, 770, 798), 
                   Upper_secondary_school_qualification = c(626, 605, 645, 688, 722, 761, 805), 
                   Level_1_3_post_school_certificate = c(631, 651, 657, 660, 672, 703, 762),
                   Level_4_6_certificate_or_diploma = c(753, 780, 763, 848, 844, 815, 863), 
                   Bachelors_degree = c(980,1006,1028, 1077, 1091, 1125, 1151), 
                   Postgraduate_qualification = c(1178, 1245, 1244, 1331, 1399, 1385, 1474))


library(plotly)
library(tidyverse)

data %>% 
  plot_ly(x = ~Year,y = ~No_Qualification, type = 'bar', name = 'No_Qualification') %>%
  add_trace(y = ~Lower_secondary_school_qualification, name = 'Lower_secondary_school_qualification') %>%
  add_trace(y = ~Upper_secondary_school_qualification, name = 'Upper_secondary_school_qualification') %>%
  add_trace(y = ~Level_1_3_post_school_certificate, name = 'Level_1_3_post_school_certificate') %>%
  add_trace(y = ~Level_4_6_certificate_or_diploma, name = 'Level_4_6_certificate_or_diploma') %>%
  add_trace(y = ~Bachelors_degree, name = 'Bachelors_degree') %>%
  add_trace(y = ~Postgraduate_qualification, name = 'Postgraduate_qualification') %>%
  layout(yaxis = list(title = 'Count'), barmode = 'group')