Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log scale #17

Open
RhettRautsaw opened this issue Dec 3, 2021 · 4 comments
Open

Log scale #17

RhettRautsaw opened this issue Dec 3, 2021 · 4 comments

Comments

@RhettRautsaw
Copy link

Is there a way to log scale a geom_fruit facet without simultaneously log scaling the underlying phylogeny?

@xiangpin
Copy link
Member

xiangpin commented Dec 6, 2021

The geom_fruit layer and the tree layer are on the same panel. the original scales x functions of ggplot2 are not compatible with geom_fruit. I think we might need to develop some similar scales functions for the x axis of geom_fruit layer. Now, I think you can use the log in the aes function, and you can refer to the example below.

library(ggplot2)
library(ggtree)
library(ggtreeExtra)

set.seed(123)
tr <- rtree(100)
dd = data.frame(id=tr$tip.label, value=abs(rnorm(100)))
p <- ggtree(tr)
p1 <- p + 
geom_fruit(
   data = dd,
   geom = geom_col,
   mapping = aes(x = log10(value), y=id),
   orientation = "y",
   offset = 0.5,
   pwidth = 0.5,
   grid.params=list(), 
   axis.params=list(axis="x", text.size = 2)
)
p1

xx

@jseidel89
Copy link

Maybe slightly in line with this question: Does this also mean that it is not possible to manually set the axis limits of geom_fruit layers? I looked into xlim_expand function (package: ggtree) but I was unable to find an equivalent to "panel"-name of this function.

@xiangpin
Copy link
Member

Yes, the axis limits of geom_fruit can not be set manually now. The grid line and axis of geom_fruit are the line layers generated by ggplot2, which are not the coord of ggplot2.

@NikoHensley
Copy link

Is there a workaround for this particular issue, especially with regards to using log-scales on data that you also want to present means and errors on (like here)? I trying to show levels of gene expression across a gene family using means + SE, but this needs a log scale because of variation between genes. Using geom_fruit_list I can either (1) generate a plot with the means and SE but many values are too small to see, (2) generate a plot with the means pre-log transformed before plotting but then the SE values are not properly mapped because they cannot come from log transformations of the calculated SE, or (3) pre-transform the raw data and plot it but then the scale is too small to see? I have attached some screenshots to demonstrate all three issues in order below:

Screenshot 2024-01-26 at 2 58 16 PM Screenshot 2024-01-26 at 2 58 27 PM Screenshot 2024-01-26 at 2 58 57 PM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants