I am having trouble creating a bar chart utilizing ggplot2
that is sorted by value.
I understand that I can order the data frame by the value and then plot it. However, ggplot2
seems to ignore the ordering.
I am using the following code:
df$Frequency <- factor(dft$Frequency, levels = df$Frequency[order(df$Frequency)])
df
# Plot the data
plot = ggplot(data=df, aes(x=Word , y=Frequency, label=Frequency)) +
geom_bar(stat="identity") +
geom_text(size = 5, position = position_stack(vjust = 1.04)) +
coord_flip()
plot
The data looks like this:
ID Word Frequency
1 70 a 194
2 48 b 116
3 139 c 104
4 293 d 87
5 12 d 87
What am I missing?