内容简介:翻译自:https://stackoverflow.com/questions/22285360/add-second-x-axis-in-ggplot2
在“图形”包中,可以向直方图添加第二个x轴(表示分布的百分位数),如下所示:
x <- rnorm(1000)
hist(x, main="", xlab="Bias")
perc <- quantile(x, seq(from=.00, to=1, by=.1))
axis(1,at=perc,labels=c("0","10%","20%","30%","40%","50%","60%","70%","80%","90%","100%"),cex=0.5, pos= -90)
当然,这看起来很尴尬.那么我怎样才能修改下面的ggplot2代码来添加第二个x轴,甩掉百分位数,而第一个x轴应该指示原始值?:
library(ggplot2) theme_classic(base_size = 12, base_family = "") x <- rnorm(1000) qplot(x, main="", xlab="Bias") perc <- quantile(x, seq(from=.00, to=1, by=.1))
有帮助吗?提前谢谢了!
我不完全确定你所追求的是什么,因为你的第一个例子并没有真正产生你描述的东西.
但就简单地沿x轴添加百分比和原始值而言,最简单的策略可能是简单地将两者与一组标签中的换行符结合起来:
dat <- data.frame(x = rnorm(1000))
perc <- quantile(dat$x,seq(from = 0,to = 1,by = 0.1))
l <- paste(round(perc,1),names(perc),sep = "\n")
> ggplot(dat,aes(x = x)) +
geom_histogram() +
scale_x_continuous(breaks = perc,labels = l)
翻译自:https://stackoverflow.com/questions/22285360/add-second-x-axis-in-ggplot2
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:- 主动模式和被动模式,添加监控主机,添加自定义模板,处理图像中的乱码,自动发现
- 苹果将为 Mac 添加 Face ID,为 Magic Keyboard 添加 Touch Bar
- android – 为什么AOSP添加新的API来支持库而不添加到SDK?
- [Framework] 添加系统服务
- go imports添加
- iOS动态添加属性
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Beginning Google Maps API 3
Gabriel Svennerberg / Apress / 2010-07-27 / $39.99
This book is about the next generation of the Google Maps API. It will provide the reader with the skills and knowledge necessary to incorporate Google Maps v3 on web pages in both desktop and mobile ......一起来看看 《Beginning Google Maps API 3》 这本书的介绍吧!