简体   繁体   English

ggplot2 facet_grid如何在每个面板中保留所有值的情况下创建不同的x轴?

[英]ggplot2 facet_grid How to create different x-axis with keeping all values in each panel?

Let's say, I have data like following example, 假设我有以下示例的数据,

dat1 <- data.frame(group = c("a", "a","a", "a", "a", "b", "b", "b","b","b","b","b","c","c","c"),
                   subgroup = c(paste0("R", rep(1:5)),paste0("R", rep(1:7)),paste0("R", rep(1:3))),
                   value = c(5,6,0,8,2,3,4,5,2,4,7,0,3,4,0),
                   pp = c("AT","BT","CT","AA","AT","TT","RT","CC","SE","DN","AA","MM","XT","QQ","HH"))

在此处输入图片说明

And, I want to add some cut off as dat1 = dat1[dat1$value > 2, ]. 而且,我想添加一些截止值作为dat1 = dat1 [dat1 $ value> 2,]。 My code 我的密码

pl <- ggplot(dat1, aes(y = as.character(pp), x = as.factor(subgroup))) + geom_point( aes(size=as.numeric(value)))+ facet_grid(cols = vars(group), scales="free", space="free")+ ylab("names") +xlab(" ") pl pl <-ggplot(dat1,aes(y = as.character(pp),x = as.factor(subgroup)))+ geom_point(aes(size = as.numeric(value)))+ facet_grid(cols = vars(组),scales =“ free”,space =“ free”)+ ylab(“ names”)+ xlab(“”)pl

enter image description here 在此处输入图片说明

But I want to see all scale in each panel. 但我想在每个面板中看到所有比例。 For example in the first panel, there are five values or five scales even if below of cut off or zero I just want to see all five scale. 例如,在第一个面板中,有五个值或五个比例,即使低于截止值或零,我也只想查看所有五个比例。 The second panel has 7 scales but after cut off, there should be 6 columns, but I want to see all 7 scales even if it has zero. 第二个面板有7个比例尺,但切除后应该有6列,但是我想查看所有7个比例尺,即使它具有零。

How can I modify my code or make as this kind of plot? 如何修改我的代码或进行这种绘图?

We can use the scales and space arguments in facet_grid . 我们可以在facet_grid使用scalesspace参数。

ggplot(dat1, aes(subgroup, pp)) +
  geom_point(aes(size = value)) +
  facet_grid(cols = vars(group), scales = "free", space = "free")

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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