I have a matrix with 10 rows and 2 columns, I want to create a bar chart which is stacked by rows but it is getting stacked by columns. This is my code for the matrix
population_matrix<-matrix(c(filter_data$Rural.population,
filter_data$Urban.population),
nrow = 10,ncol = 2,byrow = FALSE)
And, this the code for bar chart
barplot(population_matrix/1000000,
xlab = "States",ylab = "Population (in Millions)",
col = c("Green","Blue"),
main = "Statewise population",
border = "Black")
I wanted columns rural population and urban population to be stacked for each state differentiated by colors. Instead rural population got stacked in one column while urban population got stacked in another.
I believe you have data like this
and can directly do:
Data: