how bout:
dat<-data.frame(id=1:4,city=c('berlin','munich'),likeability=c(5,4,6,5),uniqueness=c(3,4,4,4))
ggplot(ddply(melt(dat,
id.vars=c('id','city')),
.(variable,city),
summarise,
value=mean(value)),
aes(x=factor(city),y=value)) +
geom_point() +
facet_wrap(~variable)
the line drawing is a bit more tricky... Since the x values are factors
rather than continuous, fitting a line to them is kind of nonsense. It
matters which order they are in for example. If instead you want to plot
something like:
ggplot(dat,aes(x=likeability,y=uniqueness,colour=city))+geom_point()+geom_smooth(aes(group=city),method='lm')
You could draw fit lines that make a bit more sense. Forgive me if I'm
over simplifying your problem!
Justin
On Thu, Jan 5, 2012 at 7:46 AM, Mario Giesel <rr.giesel@yahoo.de> wrote:
> Hello, R friends,
>
> I've been struggling quite a bit with ggplot2.
> Having worked through Hadleys book twice I still wonder how to solve this
> task.
>
>
> 1. Short example Dataframe:
>
> id city Likeability Uniqueness
> 1 Berlin 5 3
> 2 Munich 4 4
> 3 Berlin 6 4
> 4 Munich 5 4
>
> 2. Task:
>
> a) Facetting plots for each attitude (1 plot for likeability and
> uniqueness each, horizontally on one page)
> b) Showing Berlin and Munich together on x axis
> c) Showing the means of Berlin and Munich on y axis (means of cities in
> likeability on first plot, means of cities in uniqueness on second plot)
> d) Drawing a line through mean points on each plot
>
>
>
> Hope I could explain it understandably. Any help is appreciated!
>
> Thanks a lot,
> Mario
>
> [[alternative HTML version deleted]]
>
>
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>
[[alternative HTML version deleted]]