Re: ggplot2: Error: geom_line requires the following missing aesthetics: y

7,191 views
Skip to first unread message

Ben Bond-Lamberty

unread,
Dec 4, 2012, 10:00:34 AM12/4/12
to ggp...@googlegroups.com
Your data only have a single column of values, but you're trying to
use geom_point, i.e. an x-y plot. So ggplot simply doesn't have enough
data to make your requested plot.

What do you want to do? A histogram?
Ben


On Tue, Dec 4, 2012 at 8:04 AM, Jane <janeco...@googlemail.com> wrote:
> Hi all,
>
> I am trying to plot the below dataframe
>
> plot.data <- data.frame(rate.data, time.data)
>
> where rate.data is an imported file contain rate data in scientific format
> (attached) and time.data is the sequence 0:215, as there are 216 rates
> available. When I plot with the standard R plot, manage to obtain the
> expected graph however with ggplot I keep running into an error. This is my
> ggplot code:
>
> rate.plot <- ggplot(plot.data, aes(x=time.data, y=rate.data))
> rate.plot <- rate.plot + geom_point(aes(y=rate.data)) + scale_y_continuous()
> + scale_x_continuous()
>
> When I type rate.plot I get the error:
>
> Error: geom_point requires the following missing aesthetics: y
>
> Can anyone help me sort this out?
> Thanks in advance,
> Jane
>
>
>
> --
> You received this message because you are subscribed to the ggplot2 mailing
> list.
> Please provide a reproducible example:
> https://github.com/hadley/devtools/wiki/Reproducibility
>
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2

Jane

unread,
Dec 4, 2012, 10:46:22 AM12/4/12
to ggp...@googlegroups.com
I want an x-y plot, with time.data as the the x-values and rate.data as the y-values.

Jane

Brandon Hurr

unread,
Dec 4, 2012, 10:59:06 AM12/4/12
to Jane, ggplot2
I don't get an error. 

R version 2.15.1 (2012-06-22)
Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] ggplot2_0.9.2.1

loaded via a namespace (and not attached):
 [1] colorspace_1.1-1   dichromat_1.2-4    digest_0.5.2       grid_2.15.1        gtable_0.1.1       labeling_0.1      
 [7] MASS_7.3-21        memoise_0.1 
munsell_0.4        plyr_1.7.1         proto_0.3-9.2      RColorBrewer_1.0-5
[13] reshape2_1.2.1     scales_0.2.2       stringr_0.6.1
    Inline image 2

plot.data<-structure(list(data = structure(list(rate.data = c(5.45396e-05, 
2.9665e-05, 1.31932e-05, 4.72514e-06, 1.25356e-06, 2.13459e-07, 
1.85554e-08, 6.47955e-10, 2.43775e-11, 7.84186e-12, 4.69018e-12, 
2.90863e-12, 1.83848e-12, 1.17585e-12, 7.59432e-13, 4.94464e-13, 
3.25339e-13, 2.49733e-13, 4.89469e-13, 2.08148e-12, 7.28271e-12, 
1.60463e-11, 2.69434e-11, 4.00153e-11, 5.64308e-11, 7.74156e-11, 
1.03748e-10, 1.36067e-10, 1.74003e-10, 2.16835e-10, 2.63445e-10, 
3.11526e-10, 3.57677e-10, 4.0002e-10, 4.3404e-10, 4.57902e-10, 
4.69167e-10, 4.66522e-10, 4.50052e-10, 4.20478e-10, 3.80485e-10, 
3.32686e-10, 2.80735e-10, 2.27799e-10, 1.77205e-10, 1.31313e-10, 
9.17999e-11, 5.97253e-11, 3.52564e-11, 1.80752e-11, 7.40307e-12, 
2.05192e-12, 2.79908e-13, 1.67885e-14, 2.97488e-15, 1.66567e-15, 
1.17372e-15, 8.32926e-16, 5.89179e-16, 4.17018e-16, 2.9533e-16, 
2.09267e-16, 1.48365e-16, 1.05243e-16, 7.46942e-17, 5.30406e-17, 
3.76837e-17, 2.67869e-17, 1.90507e-17, 1.35555e-17, 9.65024e-18, 
6.87346e-18, 4.89807e-18, 3.4921e-18, 2.49092e-18, 1.77764e-18, 
1.26921e-18, 9.0664e-19, 6.47953e-19, 4.63297e-19, 3.31424e-19, 
2.372e-19, 1.69846e-19, 1.21675e-19, 8.7208e-20, 6.25346e-20, 
4.48636e-20, 3.21069e-20, 3.78089e-20, 4.26781e-18, 1.80484e-15, 
5.91094e-14, 3.95881e-13, 1.21812e-12, 2.5158e-12, 4.17739e-12, 
6.10973e-12, 8.25948e-12, 1.0601e-11, 1.31116e-11, 1.57553e-11, 
1.84676e-11, 2.11674e-11, 2.37433e-11, 2.60681e-11, 2.8017e-11, 
2.94623e-11, 3.03094e-11, 3.04857e-11, 2.99553e-11, 2.87262e-11, 
2.68507e-11, 2.44265e-11, 2.15849e-11, 1.8479e-11, 1.52695e-11, 
1.21238e-11, 9.18242e-12, 6.56607e-12, 4.36254e-12, 2.62022e-12, 
1.35818e-12, 5.56648e-13, 1.51794e-13, 1.9597e-14, 8.85527e-16, 
1.16283e-16, 6.32415e-17, 4.58008e-17, 3.33409e-17, 2.42273e-17, 
1.76141e-17, 1.28121e-17, 9.3236e-18, 6.78816e-18, 4.94453e-18, 
3.60333e-18, 2.62717e-18, 1.91637e-18, 1.39855e-18, 1.02114e-18, 
7.45936e-19, 5.45163e-19, 3.98623e-19, 2.91615e-19, 2.13437e-19, 
1.56294e-19, 1.14506e-19, 8.3933e-20, 6.15535e-20, 4.51639e-20, 
3.31551e-20, 2.43517e-20, 1.7895e-20, 1.31571e-20, 9.67857e-21, 
7.12347e-21, 5.24567e-21, 3.86493e-21, 2.83904e-21, 4.96934e-21, 
1.00659e-18, 4.66412e-16, 1.50704e-14, 1.02245e-13, 3.21492e-13, 
6.79211e-13, 1.15308e-12, 1.7246e-12, 2.38448e-12, 3.12877e-12, 
3.9488e-12, 4.82742e-12, 5.73639e-12, 6.63883e-12, 7.4911e-12, 
8.24719e-12, 8.86438e-12, 9.3039e-12, 9.5377e-12, 9.54866e-12, 
9.33263e-12, 8.89914e-12, 8.2725e-12, 7.48504e-12, 6.58202e-12, 
5.60985e-12, 4.61789e-12, 3.65522e-12, 2.76236e-12, 1.97181e-12, 
1.30912e-12, 7.86747e-13, 4.08844e-13, 1.68645e-13, 4.67027e-14, 
6.26758e-15, 3.11022e-16, 5.13457e-17, 3.11763e-17, 2.30185e-17, 
1.71392e-17, 1.2717e-17, 9.44112e-18, 7.01295e-18, 5.21215e-18, 
3.8759e-18, 2.88381e-18, 2.14684e-18, 1.59908e-18, 1.19173e-18, 
8.88642e-19, 6.62998e-19, 4.94921e-19, 3.69656e-19), time.data = 1:215), .Names = c("rate.data", 
"time.data"), row.names = c(NA, -215L), class = "data.frame"), 
    layers = list(<environment>), scales = <S4 object of class structure("Scales", package = "ggplot2")>, 
    mapping = structure(list(x = time.data, y = rate.data), .Names = c("x", 
    "y"), class = "uneval"), theme = list(), coordinates = structure(list(
        limits = structure(list(x = NULL, y = NULL), .Names = c("x", 
        "y"))), .Names = "limits", class = c("cartesian", "coord"
    )), facet = structure(list(shrink = TRUE), .Names = "shrink", class = c("null", 
    "facet")), plot_env = <environment>, labels = structure(list(
        x = "time.data", y = "rate.data"), .Names = c("x", "y"
    ))), .Names = c("data", "layers", "scales", "mapping", "theme", 
"coordinates", "facet", "plot_env", "labels"), class = c("gg", 
"ggplot"))
image.png

Jane

unread,
Dec 4, 2012, 11:55:00 AM12/4/12
to ggp...@googlegroups.com, Jane
I cannot reproduce what you have posted - although I'm not familiar with plotting this way, especially using the structure function. I get errors that relate to the syntax used. For example:

Error: unexpected '<' in "plot.data <- structure(list(data=structure(list(rate.data), time.data=1:215), .Names=c("rate.data", "time.data"), row.names=c(NA, -215L), class="data.frame"),  layers = list(<"

I imported the rate data using read.table into the rate.data variable.  

Thanks,
Jane

Winston Chang

unread,
Dec 4, 2012, 12:12:27 PM12/4/12
to Jane, ggplot2
The structure() part is from the output of dput() - see here for more information: 


Jane

--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility
 
Reply all
Reply to author
Forward
0 new messages