Reputation: 1930
I just started with R , I use RStudio.
Right now I am playing around with plots just to see how they work.
Here is my data:
https://www.dropbox.com/s/wp4gs8qamdo1irk/State_Zhvi_Summary_AllHomes.csv?dl=0
I have been trying to draw a barplot for $Zhvi against $RegionName
Here is my code :
labels <- allHomet$RegionName
mp<-barplot(round((allHomet$Zhvi)/1000,digits=2)[order(labels)],horiz=TRUE,las=1,col=c(palette(heat.colors(6,alpha=1))),
border=NA,
main="Price of housing in United states",
xlab="Price",
las=2 )!
I don't get region name on the y axis,it shows blank .
Can any one tell me how I can make the region name appear?
Upvotes: 0
Views: 2278
Reputation: 4987
This is a problem that ggplot2 is ideally suited to dealing with. Its flexibility and modularity make it easy to knock-up graphs like this in no time:
library(ggplot2) # load graphics package
head(df)
fl <- as.character(rep(1:6, length.out = nrow(df))) # fill variable - anything here
ggplot(df) +
geom_bar(aes(x = RegionName, y = Zhvi, fill = fl), stat = "identity", position = "dodge") +
scale_fill_brewer(type = "qual", name = "") + # customise colours and legend title
coord_flip() # make bars horizontal
Upvotes: 1