I wish to log transform my data but have an axis with linear values that correspond to the log ticks. For example, in page 3 of the following PDF from Iversen and Soskice 2002. The data has been transformed, but the labels are in their corresponding linear values for readability.
http://faculty.washington.edu/cadolph/vis/vishw1.pdf
Here is some reproducible data and my start to the plot:
set.seed(51)
data<-data.frame(country=letters[1:14],
poverty=runif(14,min=1,max=100),
parties=runif(14,min=1,max=10))
ggplot(data, aes(parties, poverty))+
geom_point(size=2)+
scale_x_log10()
Any ideas? I have seen other similar questions but none of them have working answers (e.g. Linear Ticks on a log plot in R's GGplot).
Try trans
inside scale_x_contineous
, which transform axis only.
ggplot(data, aes(parties, poverty))+
geom_point(size=2)+
scale_x_continuous(
trans = "log10",
breaks = 1:10
)
This is similar to the other two answers, but gives you something a little different:
ggplot(data, aes(parties, poverty))+
geom_point(size=2)+
scale_x_log10(breaks = scales::log_breaks(n = 10)) +
annotation_logticks(sides = "b")
if you want it on both the x and y axis then you need to add:
scale_y_log10(breaks = scales::log_breaks(n = 10))
and change sides = "b"
to sides = "bl"
in the annotation_logticks()
function.
coord_trans
does exactly that:
ggplot(data, aes(parties, poverty))+
geom_point(size=2)+
coord_trans(x = 'log10')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With