r - Constructing a graph with metric units using ggplot2 -


i constructed data frame , scatterplot using following code:

maltose_mg = c(0, 0.4, 0.8, 1.2, 1.6, 2.0)  a540 = c(0, 0.090, 0.202, 0.329, 0.395, 0.468)  df = data.frame(maltose_mg, abs540)  ggplot(df, aes(x=maltose (mg), y=a540)) +     geom_point(shape=1) +         geom_smooth(method=lm) 

unfortunately, r interprets (mg) unit designation function call , a540 unknown object. suggestions appreciated. 'lm' function line of best fit?

my goal construct aesthetically pleasing scatterplot x-axis label of maltose (mg) , y-axis label of a540.

thanks,

~caitlin

first, define data frame more cleanly:

d <- data.frame(maltose_mg=maltose_mg, a540=a540) 

(see names(d) , names(df) see why. note naming data frame df possibly bad idea, because df name of function.)

you can use xlab , ylab functions label axes. (the aes tells columns of data frame map aesthetic; if don't specify label ggplot2 separately picks default axis label name of column mapped.)

 ggplot(d, aes(x=maltose_mg, y=a540)) +     geom_point(shape=1) +         geom_smooth(method=lm) +     xlab("maltose (mg)") +     ylab("a540") 

you can use scale_x_continuous("maltose (mg)"). lots more information in r cookbook plotting section.


Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -