about facet_grid scales

25 views
Skip to first unread message

Anil

unread,
Oct 29, 2018, 4:28:26 PM10/29/18
to ggplot2
Hi, 

Is there a way to use different scales in each panel for facet_grid? I know, scale="free". but it doesn't work. All y-axis is the same for each panel. 

Let's say I have five different panels (like  A, B, C, D, E). In these panels, for example, I have 8 columns in A panel,  12 columns in B, 5 columns in C, 8 in D, 8 in E. 
Let's say, 3 columns have data but 5 columns have zero in A. 11 columns have data, one is zero in B panel. And I want to show all columns for each panel (even if zero) but panels have different scales. 
And when I tried scales="free_x", only columns which have data, (not zero ones) come in the figure. 


Brandon Hurr

unread,
Oct 29, 2018, 8:59:28 PM10/29/18
to ani...@gmail.com, ggp...@googlegroups.com
Anil, 

Do you have an example dataset that is like your data or can you share your data publicly? 

Could you see the link in the bottom of this email about submitting a reproducible example for how to do this best.

Thanks, 
Brandon


--
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility
 
To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2

---
You received this message because you are subscribed to the Google Groups "ggplot2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ggplot2+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

tric...@uni-bremen.de

unread,
Oct 30, 2018, 4:22:27 AM10/30/18
to ggp...@googlegroups.com
I am pretty sure, Anil refers to this problem:
https://stackoverflow.com/questions/30196143/bars-in-geom-bar-have-unwanted-different-widths-when-using-facet-wrap

Hope this helps, Tim


Zitat von Brandon Hurr <brando...@gmail.com>:
> --



Anil Aktas Samur

unread,
Oct 30, 2018, 10:38:36 AM10/30/18
to tric...@uni-bremen.de, ggp...@googlegroups.com
let's say my data is 

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"))
When I use following 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))+
  ylab("names") +xlab(" ")
  pl 
 My figure is attached as "Denemeplot". But I want to add some cut off as 
dat1 <- dat1[dat1$value >2 , ] and 

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 
My figure is now as "denemeplot2"

But I want to all values with scales of each panel also even if zero. For example in the second plot, the first panel has five value, so I want to see all scale in the first panel, etc. 

How can I make this plot? 

Thanks, 
Anil 


Denemeplot.png
denemeplot2.png
Reply all
Reply to author
Forward
0 new messages