I'm trying to create a data visualisation to show the number of schools broken down by the number of classes. I created a tibble that does this (I've pasted below) Where there are two columns, 'c(grade5$schlcode)' which shows a list of the unique school codes and 'n' which is the number of classes within each school code.
n_classes <- count(grade5, c(grade5$schlcode))
>
> n_classes
# A tibble: 1,002 x 2
`c(grade5$schlcode)` n
<dbl> <int>
1 11005 2
2 11006 2
3 11009 1
4 11010 2
5 11013 3
6 11015 3
7 11017 2
8 11020 3
9 11021 2
10 11027 3
# … with 992 more rows
I then tallied the number of schools in order to create a tibble
to make this barplot
.
> x <- count(n_classes, c(n_classes$n))
> x
# A tibble: 6 x 2
`c(n_classes$n)` n
<int> <int>
1 1 296
2 2 456
3 3 199
4 4 42
5 5 8
6 6 1
But when I make the plot it shows correctly the frequency of schools that have 1 class and 2 classes and 3 classes and so on, but i has not displayed the units of X axis (so each bar should be labelled 1, 2, 3, 4 (classes). But there's no units only the xlab!
> barplot(x$n, x$`c(n_classes$n)`,
+ xlab = "Number of Classes in a School",
+ ylab = "Frequency of Schools",
+ main = "Number of Classes Schools Have",
+ col = "grey",
+ border = "orange")
How can I fix this?