ggplot中的辅助轴上的其他变量(不是主轴变量的变换值) [英] Different variable, not the transformed value of primary axis variable, on secondary axis in ggplot

查看:50
本文介绍了ggplot中的辅助轴上的其他变量(不是主轴变量的变换值)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在辅助轴上添加一个不同的变量,但似乎仅使用参数sec仅取主轴的一些转换值即可.轴= sec_axis(trans =〜.(+/-/*等)).运行代码直到coord_flip().在该图表中,我要在主要轴上显示mpg,在次要轴上显示disp.我该怎么办?

I want to add a different variable on secondary axis, but it seems it only takes some transformed value of primary axis only using the argument sec.axis = sec_axis(trans = ~.(+/-/*, etc)). Run the code up until the coord_flip(). In that chart, I want mpg on primary and disp on secondary axis. How can I do that?

library(tidyverse)
mtcars %>% 
  rownames_to_column() %>% 
  slice(1:5) %>%
  ggplot(aes(x=rowname)) +
  geom_col(aes(y = mpg, fill = factor(carb)), position = "stack") +
  geom_point(aes(y = disp), color = "Orange", size = 5) +
  coord_flip() +
  scale_y_continuous(sec.axis = sec_axis(~ disp_doesn't_word_here))

推荐答案

库(tidyverse)这个怎么样?您可以根据需要调整值.

library(tidyverse) How about this? You can adjust values for your need.

mtcars %>% 
  rownames_to_column() %>% 
  slice(1:5) %>%
  ggplot(aes(x=rowname)) +
  geom_col(aes(y = mpg, fill = factor(carb)), position = "stack") +
  geom_point(aes(y = disp/10), color = "Orange", size = 5) +
  coord_flip() +
  scale_y_continuous(sec.axis = sec_axis(~ .*10))

这篇关于ggplot中的辅助轴上的其他变量(不是主轴变量的变换值)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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