0
votes

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"))

enter image description here

And, I want to add some cut off as 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

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.

How can I modify my code or make as this kind of plot?

1

1 Answers

2
votes

We can use the scales and space arguments in facet_grid.

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

enter image description here