Plotting polygons in R when y range is character vector -
Plotting polygons in R when y range is character vector -
i have plotting code i've used before info numeric or integer. have similar info except 1 column character data, ?polygon says can use. i've been wrestling , can't solve errors i'm getting. help, please!
my info is:
dem.plotting <- data.frame( group=c(1, 1, 1, 2, 2, 2, 3, 3, 3), year=c("2012", "dem", "non-dem", "2012", "dem", "non-dem", "2012", "dem", "non-dem"), mingdp=c(17.1, 17.3, 20.2, 19.8, 20.3, 21.7, 20.7, 21.7, 22.6), maxgdp=c(19.4, 20.3, 21.5, 20.5, 21.3, 21.9, 21.4, 22.5, 22.3), data=data.frame(group, year, mingdp, maxgdp))
this code i've used before isn't working now:
yrange = range(dem.plotting$year) xrange = range(dem.plotting[,3:4]) plot(year~mingdp,data=dem.plotting,type="n",xlab="log(gdp)",ylab="year", ylim=yrange,xlim=xrange) dens = c(na,20,40,na,20,40,na,20) ang = rep(45,times=8) fillcol = c("white","gray","gray","black","black","black","white","gray") (i in 1:nrow(dem.plotting)){ with(dem.plotting[i,],polygon(x=c(mingdp,maxgdp,maxgdp,mingdp), y=c(year+0.25,year+0.25,year-0.25,year-0.25), density=dens[group],ang=ang, col=fillcol[group], border="black" ) ) }
i next error trying set empty plot:
error in plot.window(...) : invalid 'ylim' value in addition: warning message: in xy.coords(x, y, xlabel, ylabel, log) : nas introduced coercion
so r doesn't having character vector 'year', , don't know how prepare that, , error generated when trying plot polygons:
error in year + 0.25 : non-numeric argument binary operator
i understand doesn't 'year' character, , not numeric, thought plot polygons using character info vertices?
any help appreciated!
r polygons
Comments
Post a Comment