I am plotting a multiple grouping bar chart and finding that, although the data is displaying correctly, the chart is completely skewed in it's display because the y-axis tick values are not in numerical order.
Current graph output:
Below is my code, can anyone show me how I can order the values numerically?
library(ggplot2)
veg_db <- read.csv("filepath\\filename.csv", header = TRUE)
veg_df <- data.frame(veg_db)
veg <- veg_df[c(125),c(4,5,9,12,13,18)]
white_veg <- data.frame(t(veg))
colnames(white_veg) <- c("value")
rownames(white_veg) <- c("Broccoli", "Carrots", "Leafy Greens", "Peas", "Peppers", "Tomatoes")
white_veg <- cbind(vegetables = rownames(white_veg),ethnicity = "white", white_veg)
veg <- veg_df[c(129),c(4,5,9,12,13,18)]
black_veg <- data.frame(t(veg))
colnames(black_veg) <- c("value")
rownames(black_veg) <- c("Broccoli", "Carrots", "Leafy Greens", "Peas", "Peppers", "Tomatoes")
black_veg <- cbind(vegetables = rownames(black_veg),ethnicity = "black", black_veg)
total_veg <- merge(white_veg, black_veg, all = TRUE)
total_veg
plot <- ggplot(total_veg, aes(vegetables, value, fill = ethnicity))+
geom_bar(position="dodge",stat="identity")
plot
Here is the output of my total_veg dataframe:
total_veg
vegetables ethnicity value
1 Broccoli white 10.18
2 Broccoli black 6.46
3 Carrots white 12.58
4 Carrots black 8.54
5 Leafy Greens white 2.88
6 Leafy Greens black 1.68
7 Peas white 19.96
8 Peas black 13.13
9 Peppers white 3.09
10 Peppers black 3.12
11 Tomatoes white 80.13
12 Tomatoes black 62.08