Plotting a data frame in R

272 views Asked by At

I have this data frame and I'd like to know if there's a way to plot this using the ggplot2 library (or anything that works). The first row has a bunch of zip codes and the second row contains weather data (temperature in this case) associated with the corresponding zip code. I want to create a graph (bar/plot) with the zip codes on the x axis and the temperature values on the y axis but I don't know how to do it.

     V1   V2
1  20904 82.9
2  20905 80.1
3  20906 84.6
4  20907 84.6
5  20908 88.0
6  20910 84.6
7  20911 84.6
8  20912 86.1
9  20913 86.1
10 20914 80.7
11 20915 84.6
1

There are 1 answers

4
Robert On BEST ANSWER

You also can do a simple barplot:

ydf <- ZipGraph

barplot(ydf[2,],names.arg = ydf[1,],col=rainbow(ncol(ydf)),
        xlab="zipcode",ylab="Temperature",cex.axis = .8,cex.names = .7)

Edit: Or you can do

ylims=c(0,max(ydf[,2])*1.2)
y1=barplot(ydf[,2],col=rainbow(nrow(ydf)),xaxt="n",ylim=ylims,
        xlab="zipcode",ylab="Temperature",cex.axis = .8)
axis(1, at=y1,labels=ydf[,1],las=2,cex.axis= .6)