Ggplot2 scale correlation settings-coordinate transformation
There are several forms of axis conversion in R, including logarithmic conversion, square root conversion, and pre-and post-scale exchange of coordinates.
The functions used are:
SCALE_X_LOG10 (...) SCALE_Y_LOG10 (...) Scale_x_sqrt (...) Scale_y_sqrt (...) Scale_x_reverse (...) Scale_y_reverse (...) The above functions are actually based on scale_x_continuous (name = Waiver (), breaks = Waiver (), Minor_breaks = Waiver (), labels = WA Iver (), limits = NULL, expand = Waiver (), OOB = censor, Na.value = na_real_, trans = "Identity") the parameter trans can achieve the same effect as IRI s data set as an example
P<-ggplot (Iris,aes (petal.length,petal.width)) +geom_point () p
The effect of the standard case
P+SCALE_X_LOG10 () p+scale_x_continuous (trans= "log10")
The effect of the above two lines of code is the same, that is, the function x-axis to do a logarithmic conversion, the effect is as follows
In addition, with the scales package, you can make a richer scale setting
Library (scales) p+scale_x_continuous (Trans=log2_trans (), labels=percent)
In addition, with the Coord_trans () function, you can set the X and Y axes directly
P+scale_x_continuous (Trans=log2_trans (), labels=percent) + scale_y_continuous (labels=dollar) P+coord_trans (x= "Log2", y= "sqrt")
These are the drawing effects of the last two functions. Overall, the scale conversion setup process is relatively simple, and the frequency may also be relatively small, a little bit to understand.
Ggplot2 scale correlation settings-coordinate transformation