0

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.

enter image description here enter image description here

Sal-laS
  • 11,016
  • 25
  • 99
  • 169

1 Answers1

0

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())

enter image description here

Sal-laS
  • 11,016
  • 25
  • 99
  • 169
  • sorry I cant use fill , bcuz these are two different columns. I used reshape and scales for this particular graph – Fatma Zahra Aug 26 '18 at 07:19
  • @FatmaZahra do you know `ggplot`? – Sal-laS Aug 26 '18 at 07:33
  • yes I know . but i dont know how to make a cluster barchart in ggplot\ – Fatma Zahra Aug 26 '18 at 07:34
  • so should i add a column called category ? – Fatma Zahra Aug 26 '18 at 07:41
  • @FatmaZahra Yes, for sure. the `category` is your groups. If you dont do that, then `ggplot` does not understand how to cluster your bars. please accept my answer if it was helpful. – Sal-laS Aug 26 '18 at 07:42
  • thank you ! and what if i have to display the difference of each month in another plot ? – Fatma Zahra Aug 26 '18 at 07:45
  • and since i am importing the table from excel I donno how to add the category column – Fatma Zahra Aug 26 '18 at 07:47
  • About importing data from excel. There is no easy way. You either must write so `R` code to fix you dataset pragmatically, or spend time and do it manually. – Sal-laS Aug 26 '18 at 07:49
  • @FatmaZahra about making another plot, it is better to ask another question for it. I think, you must fill the barcharts with the different values, but i am not sure if i get you correctly or not. – Sal-laS Aug 26 '18 at 07:52