[R] ggplot2::qplot() -- arbitary transformations of coordinate system?

Michael Kubovy kubovy at virginia.edu
Sun Sep 6 13:30:41 CEST 2009


Hi Stephen,

Because coord_trans() does all the work of plotting the original  
values on the tranformed scale. See ?coord_trans. To quote: "The  
difference between transforming the scales and transforming the  
coordinate system is that scale transformation occurs BEFORE  
statistics, and coordinate transformation afterwards."

# After
require(ggplot2)
data(diamonds)
# Three ways of doing transformating in ggplot:
# * by transforming the data
qplot(log10(carat), log10(price), data=diamonds)
# * by transforming the scales
qplot(carat, price, data=diamonds, log="xy")
qplot(carat, price, data=diamonds) + scale_x_log10() + scale_y_log10()
# * by transforming the coordinate system:
qplot(carat, price, data=diamonds) + coord_trans(x = "log10", y =  
"log10")

Michael

On Sep 5, 2009, at 9:01 PM, stephen sefick wrote:

> why not transform the y-data?
>
> On Sat, Sep 5, 2009 at 8:03 PM, Michael Kubovy<kubovy at virginia.edu>  
> wrote:
>> Hi,
>>
>> Does anyone know how to do a coord_trans() in which the y-axis is  
>> tranformed
>> into (for example) -1000/y?

> Stephen Sefick



_____________________________
Professor Michael Kubovy
University of Virginia
Department of Psychology
USPS:     P.O.Box 400400    Charlottesville, VA 22904-4400
Parcels:    Room 102        Gilmer Hall
       McCormick Road    Charlottesville, VA 22903
Office:    B011    +1-434-982-4729
Lab:        B019    +1-434-982-4751
Fax:        +1-434-982-4766
WWW:    http://www.people.virginia.edu/~mk9y/




More information about the R-help mailing list