在ggplot2中的轴标记上显示两个测量单位 [英] Show two measurement units on axis ticks in ggplot2

查看:148
本文介绍了在ggplot2中的轴标记上显示两个测量单位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在ggplot2中,如何可能(如果有的话)在坐标轴上显示两个可选单位?
我想达到的是这样的:



解决方案



  d = data.frame(x = 1:20,y = rnorm(20,5,5))

ggplot( data = d,aes(x = x,y = y))+
scale_x_continuous(breaks = c(1:20,seq(2.54,20,2.54)),
labels = c(1: 20,paste0(\ n,1:as.integer(20 / 2.54),\)))+
geom_point()
pre>


How it is possible (if at all) to show two alternative units on axis ticks in ggplot2? What I would like to achieve is something like this:

解决方案

Here's a hacky way of doing that:

d = data.frame(x = 1:20, y = rnorm(20, 5, 5))

ggplot(data = d, aes(x = x, y = y)) +
  scale_x_continuous(breaks = c(1:20, seq(2.54, 20, 2.54)),
                     labels = c(1:20, paste0("\n", 1:as.integer(20/2.54), "\""))) +
  geom_point()

这篇关于在ggplot2中的轴标记上显示两个测量单位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆