Simple question about geom_line

59 views
Skip to first unread message

Eiko Fried

unread,
Feb 25, 2015, 11:56:08 AM2/25/15
to ggp...@googlegroups.com
Hi everybody. 

a <-c("ene", "sad", "sym", "int", "ple", "con", "pan", "app", "in2", "anx", "bla", "in3", "par", "in1", "ret", "inp", "rea", "sui", "pes", "som", "irr", "wei", "agi", "sex", "hyp", "gas", "var", "qua")
b <-c(1.15220099, 1.10797504,1.05083488, 1.04075482, 1.04040974, 1.03017191, 1.00986077,0.97687106, 0.97651034, 0.96653016, 0.91066171,0.87499607, 0.82549958, 0.79714062, 0.76731441, 0.74983882, 0.73617558, 0.72655416, 0.70751901, 0.68061369, 0.67726459, 0.65987862, 0.6046725, 0.586737, 0.56771942, 0.46720748, 0.1767481, 0.08969517)

plot1 <- transform(plot, a = reorder(a, order(b, decreasing = T)))

ggplot(plot1, aes(x=as.factor(a), y=b, order=a))+
  geom_bar(stat="identity",fill='#888888',colour='#888888')

works well. 

I can't get a simple line to work though: 
ggplot(plot1, aes(x=as.factor(a), y=b, order=a))+
  geom_line() 

"geom_path: Each group consist of only one observation. Do you need to adjust the group aesthetic?"

I don't have any groups, so the error message does not make sense to me (googling it I find hundreds of hits, but all for very different problems). 

Thanks for helping out
  Eiko


Ista Zahn

unread,
Feb 25, 2015, 12:22:35 PM2/25/15
to Eiko Fried, ggplot2
The group aesthetic is set to the interaction of all categorical
variables by default. You need to overide it, like this:

ggplot(plot1, aes(x=as.factor(a), y=b, order=a))+
geom_line(aes(group = 1))


Best,
Ista
> --
> --
> 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
>
> ---
> You received this message because you are subscribed to the Google Groups
> "ggplot2" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ggplot2+u...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Eiko Fried

unread,
Feb 27, 2015, 9:16:24 AM2/27/15
to ggp...@googlegroups.com, eiko....@gmail.com
Ista, thank you very much. The line looks "smoothed", but for me each factor (x-axis) needs a distinct value, if you know what I mean. So I'd rather have a non-smoothed line. Any idea on how to do that? 

# a=variable names
# b=values

ggplot(df, aes(x=as.factor(a), y=b, order=a))+
  geom_line(aes(group=1)) 

Eiko Fried

unread,
Feb 27, 2015, 9:39:39 AM2/27/15
to ggp...@googlegroups.com, eiko....@gmail.com
And where do you add color and size?

Adding it in the aes bracket doesn't work:
ggplot(df, aes(x=as.factor(a), y=b, order=a))+
  geom_line(aes(group=1, colour="red"))

Adding it outside the bracket doesn't work:
ggplot(df, aes(x=as.factor(a), y=b, order=a))+
  geom_line(aes(group=1),  colour="red")
 
Thank you!

Ista Zahn

unread,
Feb 27, 2015, 10:45:35 AM2/27/15
to Eiko Fried, ggplot2
On Fri, Feb 27, 2015 at 9:16 AM, Eiko Fried <eiko....@gmail.com> wrote:
> Ista, thank you very much. The line looks "smoothed", but for me each factor
> (x-axis) needs a distinct value, if you know what I mean.

I'm afraid I don't follow. The lines just connect the points, as you
can see with

ggplot(plot1, aes(x=as.factor(a), y=b, order=a))+
geom_line(aes(group = 1), colour = "red") +
geom_point()

no smoothing was done.

Best,
Ista

So I'd rather have
> a non-smoothed line. Any idea on how to do that?
>
> # a=variable names
> # b=values
>
> ggplot(df, aes(x=as.factor(a), y=b, order=a))+
> geom_line(aes(group=1))
>

Ista Zahn

unread,
Feb 27, 2015, 10:46:10 AM2/27/15
to Eiko Fried, ggplot2
ggplot(plot1, aes(x=as.factor(a), y=b, order=a))+
geom_line(aes(group=1), colour="red")


works for me.

Best,
Ista
Reply all
Reply to author
Forward
0 new messages