[R] Plotting from different data sources on the same plot (with ggplot2)
jo.irisson at gmail.com
Mon Oct 1 07:53:16 CEST 2007
This would probably also be interesting to some:
On 2007-October-01 , at 00:48 , hadley wickham wrote:
>> That's great!
>> In fact I think I found exactly what I was looking for. I can just
>> p = ggplot() + coord_equal()
>> p$aspect.ratio = 1
>> to set up the plot, and then add the layers and have ggplot take care
>> of resizing and laying out everything automagically:
>> p = p + geom_path(data=coast, mapping=aes(x=lon, y=lat))
>> p = p + geom_point(data=coords, mapping=aes(x=lon, y=lat))
>> p = p + geom_text(data=coords, mapping=aes(x=lon, y=lat,
>> Oh, I love ggplot ;) !
> Or even less verbosely:
> p = ggplot(mapping = aes(x=lon, y= lat) + coord_equal()
> p = p + geom_path(data=coast)
> p = p + geom_point(data=coords)
> p = p + geom_text(data=coords, aes(label = station))
>>> The data is completely independent of the plot specification.
>>> This is
>>> very different from the other plotting models in R, so it may take a
>>> while to get your head around it.
>> Yes, indeed. That's a completely new way of thinking (especially
>> given my MATLAB, Scilab background) but how powerful! I found the
>> whole "data mapping" concept very elegant but did not grasp all the
>> flexibility behind it. I wonder how mainstream it can get since so
>> many people are used to an other graphics paradigm.
> It's definitely a big change, but I hope that people will see the
> potential benefits and invest some time learning it. I definitely
> have a lot to improve on the documentation though!
>> Anyway, I just need to define a new geom_arrow now, to plot wind
>> velocities arrows at several locations, and I'll be a happy man. Is
>> there a specific reason why '...' arguments are not passed to grid
>> functions or is it just to keep the complexity under control? I am
>> thinking in particular that:
>> p = ggplot(coords) + geom_segment(mapping=aes(x=lon,
>> y=lat, xend=lon
>> +0.03 ,yend=lat+-0.02), arrow=arrow(length=unit(0.1,"inches")))
>> would do exactly what I want provided that the 'arrow' argument is
>> passed on to segmentsGrob which is used in geom_segment.
> In general, ... doesn't get passed on to the underlying grid function
> because there isn't a one-to-one mapping from geoms to grobs (take
> geom_boxplot for example). However, funnily enough, I have just added
> the arrows argument to geom_segment for my sister, so if you let me
> know what platform you're on, I can send you an updated version.
More information about the R-help