Search code examples
rcharacterbar-chartnumeric

Trying to plot a bar chart in R with "character" on x axis and "factors" on y axis


Degrees: ME, BE, EMPS, NAME, EIM, EC, MA, MH, OE, RC, CFS, AS

Income: 73926, 97410, 74179, 75635, 78866, 54000, 44800, 45000, 46300, 46400, 46500, 47000

structure(list(Degree = c("ME", "BE", "EMPS", "NAME", "EIM", "Ec", "MA", "MH", "OE", "RC", "CFS", "AS"), Income = c(73926, 97410, 74179, 75635, 78866, 54000, 44800, 45000, 46300, 46400, 46500, 47000)), class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA, -12L))

''' barplot(data$Degrees, data$Income) '''

Newbie to R here. I am trying to replicate the bar chart below, but in R. Really struggling with this as all attempts end with the error 'argument is not numeric or logical'. Unsure what to do next and any advice would be appreciated.

enter image description here


Solution

  • Look for ggplot2 package information

    Tryed to create the code strucutre so you can edit some characteristc like texts size and etc:

    ggplot(df)+
            geom_col(aes(x = Degree, 
                         y = Income),
                     fill = "blue",
                     width = 0.7)+
            theme_classic() +
            ggtitle("Graph title",
                    subtitle = "Subtitle")+
            labs(x = "X axis title",
                 y = "Y axis title")+
            theme(axis.title = element_text(size = 15, face = "bold"),
                  axis.text = element_text(size = 10),
                  plot.title = element_text(size = 20, hjust = 0.5),
                  plot.subtitle = element_text(size = 15, hjust= 0.5))
        
    

    enter image description here