Monday 15 April 2013

r - Getting plot errors when creating custom axes -



r - Getting plot errors when creating custom axes -

i have issue creation of custom axes in base of operations plotting scheme in r, have next info frame want plot trend show changes each year:

year <- c(2000, 2002, 2005, 2009) values <- c(7332967, 5332780, 5135760, 3464206) x <- data.frame(year, values) ## year values ## 1 2000 733296 ## 2 2002 533278 ## 3 2005 513576 ## 4 2009 346420

my first effort is:

plot(x$year, x$value, xlab = "year", ylab = "value", type = "b")

however, gives me skewed x , y axis 4 values have in info frame. x axis contain 4 values under "year" column , y axis contain 4 values under "values" column.

for purpose tried create custom x , y axis resulted in errors:

plot(x$year, x$value, type = "b", xaxt = "n", yaxt = "n", xlab = "year", ylab = "values", axis(1, @ = 1:nrow(x), labels = x$year), axis(2, @ = 1:nrow(x), labels = x$value)) "error in plot.window(...) : invalid 'xlim' value"

and:

plot(x$year, x$value, type = "b", xaxt = "n", yaxt = "n", xlab = "year", ylab = "values", axis(1, @ = 1:nrow(x), labels = x$year), axis(2, @ = 1:nrow(x), labels = x$value), xlim = c(min(data_plot$year), max(data_plot$year)), ylim = c(min(data_plot$emissions), max(data_plot$emissions))) "error in strsplit(log, null) : non-character argument"

i quite new r , tried searching solutions on various sites, however, nil seems solve issue help provided much appreciated.

axis separate function, not argument plot, seek following:

# first create space on left long numeric axis labels par(mar=c(5, 6, 1, 1)) # plot points, suppress axes plot(x$year, x$values, xaxt='n', yaxt='n', xlab='year', ylab='', type='b') # add together axes axis(1, at=x$year, labels=x$year, cex.axis=0.8) axis(2, at=x$values, labels=x$values, las=1, cex.axis=0.8) # add together y label bit farther away axis title(ylab='value', line=4)

r plot

No comments:

Post a Comment