ggplot2 scale in R (grammar for graphics)

ggplot2 scale in R, due to the right-skewed distribution and selection of a linear scale in ggplot2, it is challenging to distinguish disparities in GDP.

Read previous post…

g+geom_point(aes(color=net_users,size=roadways))
g+geom_point(aes(color=net_users,size=roadways))+coord_trans(y="log10")

In the latter, the scatterplot is easier to read because of the logarithmic scale on the vertical axis. Naturally, this complicates plot interpretation, so we must exercise extreme caution.

Note that the coord_trans() directive is the sole variation in the code. Any of the scale() functions in ggplot2 can be used to change scales.

For instance, we could have produced the same plot by using the scale_y_continuous() function instead of the coord_trans() method as we did previously, as shown below.

g+geom_point(aes(color=net_users,size=roadways))+scale_y_continuous(name="GDP",trans="log10")

The only variation between the two plots is how and where the primary tick marks and axis labels are produced. In either scenario, the points will be shown in the same spot.

We prefer to do equivalent procedures on various aesthetics using coord_trans().

Not every scale focuses on position. For instance, net_users is converted to colour in the first figure.

Roadways are converted to size in a similar manner; the largest dot represents a value of five roads per unit of area.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

2 × 2 =

finnstats