I have data sheet of 3 columns - month , p1 ,p2 I need to display a grouped barplot of p1 and p2. x axis is months . I want to know how to display percentage on the graph.
I have data sheet of 3 columns - month , p1 ,p2 I need to display a grouped barplot of p1 and p2. x axis is months . I want to know how to display percentage on the graph.
The image which you have provided is called cluster barchart. You need to redefine your dataset since it does not give you the cluster barchart.
Create dataset:
dt<-data.frame(
month= c("Jan", "Feb", "Mar", "Apr","May","Jun","Jul","Agu","Sep","Oct","Nov","Dec",
"Jan", "Feb", "Mar", "Apr","May","Jun","Jul","Agu","Sep","Oct","Nov","Dec"),
category=c("P1","P1","P1","P1","P1","P1","P1","P1","P1","P1","P1","P1",
"P2","P2","P2","P2","P2","P2","P2","P2","P2","P2","P2","P2"),
value=sample(50000:100000,24))
head(dt)
and then draw it
library(ggplot2)
ggplot(data=dt, aes(x=month, y=value, fill=category)) +
geom_bar(stat="identity", position=position_dodge())