I have a "frequency table" similar to this one
# Create a matrix
df<- matrix(sample(0:10,35,replace=T),nrow=5, ncol=7)
# Rename columns and rows
colnames(df) <- c("Monday","Tuesday", "Wednesday", "Thursday", "Friday",
"Saturday", "Sunday")
row.names(df) <- c(2015, 2016, 2017, 2018, 2019)
I want to use ggplot2
in order to represent the information, but I need to transform this information into something like this:
Day Year Frequency
Monday 2015 10
Monday 2016 7
Monday 2017 13
I tried to use melt()
function from reshape2
package but I did not get what I wanted, because the second column does not appear (probably because it corresponds to the row names of the table).
Any help would be appreciated,