This is where I get my dataset and c
board_game_original<- read.csv("https://raw.githubusercontent.com/bryandmartin/STAT302/master/docs/Projects/project1_bgdataviz/board_game_raw.csv")
#tidy up the column of mechanic and category with cSplit function
library(splitstackshape)
mechanic <- board_game$mechanic
board_game_tidy <- cSplit(board_game,splitCols=c("mechanic","category"), sep = ",", direction = "long")
I am trying to make the graph more organized by ordering the bar by the values of the bar on the y-axis. I tried using the reorder function but still does not work. Does anyone have any suggestions? I am quite new to R and hope to learn more!
library(ggplot2)
average_complexity <- board_game_tidy %>%
filter(yearpublished >= 1950, users_rated >= 25, average_complexity>0 ) %>%
select(average_complexity)
category_complexity_graph <- ggplot(data=board_game_tidy, aes(x = reorder(category, -average_complexity), y = average_complexity, na.rm = TRUE)) +
geom_bar(stat = "identity", na.rm = TRUE, color="white",fill="sky blue") +
ylim(0,5) +
theme_bw() +
ggtitle("Which category of board games has the highest level of average complexity") +
xlab("category of board games") +
ylab("average complexity of the board game") +
theme(axis.text.x = element_text(size=5, angle = 45)) +
theme(plot.title = element_text(hjust = 0.5))
category_complexity_graph
Here's the graph I plot:
"Category" is a categorical variable and "average complexity" is a continuous variable.
I was trying to answer the question "which category has the highest average complexity?" but this graph looks messy and any suggestion of cleaning it up would be appreciated as well! Thank you all