简体   繁体   中英

ggplot2: how to plot in reciprocal scale

I want to use ggplot to create scatter plot where y scale to be scaled as 1/y (my y are all positive), yet labeled with original values of y . How can I do this?

I tried to plot with + scale_y_continuous(trans='recip') but got following error:

Error in get(as.character(FUN), mode = "function", envir = envir) :
object 'recip_trans' of mode 'function' was not found

Thanks,

Something like this?

library(ggplot2)
library(scales)

df = data.frame(x = c(1:46), y = seq(500, 5000, 100))

ggplot(df, aes(x, y)) +
   geom_point() +
    scale_y_continuous(trans = reciprocal_trans(), breaks = c(500, 1000, 2000, 5000))

在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM