I'm trying to draw a grouped bar plot in r
Here is my code:
xtable <- xtabs(~ view + grade, data=hs)
xtable
barplot(xtable, beside = T, legend.text = T)
library(reshape2)
data.m <- melt(xtable, id.vars='view')
data.m
# plot
ggplot(data.m, aes(grade, value)) + geom_bar(aes(fill = view),
width = 0.4, position = "dodge", stat="identity") +
theme(legend.position="top", legend.title =
element_blank(),axis.title.x=element_blank(),
axis.title.y=element_blank())
View and grade are two properties of homes sold. Grade is a value between 0 to 13 showing the rank of a home, and view is 0 to 4 showing how good is the view of the home.
The usual barplot command in r works oaky. However, I liked a ggplot for it. I followed the answer of similar questions, but I get a stacked bar instead of a grouped one. Also, how can I generate a segmented bar plot and spine plot using the same data?