I've been looking around on the site to see if there were any previous posts about ordering columns on a heat map with geom_tiles. I am trying to create a heatmap that shows occurrences of certain scales of hydrologic research within different areas in Canada. My original code is shown below.
##Hydrologic Scale Frequency Table##
data5=read.csv(file.choose())
#load ggplot2
ggplot(data5, aes(Hydrologic, Jurisdiction)) +
geom_tile(aes(x=Hydrologic, y=reorder(Jurisdiction, Rank), fill = Freq), colour = "black") +
geom_text(aes(label=Freq), color = "black") +
scale_fill_gradient(low = "white", high = "#48D1CC")
The code above does not show my columns in an order that makes sense (i.e. NA/Non distinguishable columns at the end).
When I do the following code before the geom_tiles code, it merges all columns into a single column.
col_order <- c("Basin", "Water body", "Watershed", "Non Distinguishable")
data5$Hydrologic <- factor(data5$Hydrologic, levels = col_order)
Does anyone have any advice as to how I can go about fixing my issue?