0

The table shows the first row with 12 month names and the values of visitors, with portuguese (Portugal) and foreigners (ESTRANGEIRO) (ignore the row with no names)

enter image description here

How can I plot, in ggplot2, a bar graph that shows the portuguese visitors and the foreigners visitors during the 12 month period?

amonk
  • 1,769
  • 2
  • 18
  • 27

1 Answers1

0

Usually it is better to provide some reproducible code example than to submit a screenshot, see e.g. here: Click

To accomplish what you want to do, you will have to change your format a little bit. Given a dataframe that looks like yours and using reshape2:

df <- data.frame(month=factor(c("Jan","Feb","Mar"),labels=c("Jan","Feb","Mar"),ordered=TRUE),
                 portugal=c(4000,2330,3000),
                 foreigner=c(4999,2600,3244),
                 stringsAsFactors = FALSE)


library(reshape2)
plotdf<-melt(df)
colnames(plotdf)<-c("Month","Country","Visitors")
levels(plotdf$Country)<-c("Portgual","Foreigners")

ggplot(plotdf,aes(x=Month,y=Visitors,fill=Country)) + 
  geom_bar(stat="identity",position=position_dodge()) +
  xlab("Month") +
  ylab("Visitors")

Plot

yrx1702
  • 1,619
  • 15
  • 27