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

geom_inset: scales of images vary among figures #289

Closed
fionarhuang opened this issue Apr 8, 2020 · 2 comments
Closed

geom_inset: scales of images vary among figures #289

fionarhuang opened this issue Apr 8, 2020 · 2 comments

Comments

@fionarhuang
Copy link
Contributor

Hi Y 叔,

I am wondering why the sizes of pie charts are different among figures that are supposed to have the same range of x-axis. Is it possible to make all pie charts have the same size when the same tree is used?

library(ape)
library(ggtree)
library(ggimage)
library(ggplot2)

set.seed(1)
tr <- rtree(50)
fig1 <- ggtree(tr, branch.length = "none")
fig1

n <- c(8, 10, 5, 6)
df_list <- lapply(n, FUN = function(x) {
    data.frame(node  = sample(1:99, size = x),
               A = sample(0:1, size = x, replace = TRUE),
               B = sample(0:1, size = x, replace = TRUE),
               C = sample(0:1, size = x, replace = TRUE))
})

fig_list <- vector("list", length(n))

for (i in seq_along(n)) {
    pies_i <- nodepie(data = df_list[[i]], cols = 2:4, 
                      color = c("red", "blue", "black"))
    fig_list[[i]] <- fig1 +
        geom_inset(pies_i, width = 0.2, height =  0.2)
    
}



fig_more <- plot_grid(plotlist = fig_list, nrow = 2, 
                      rel_heights = c(0.5, 0.5))
figPath <- "temp.eps"
ggsave(figPath, fig_more, units = "in", width = 8, height = 8,
       dpi = 300)

The result is as below
Screenshot 2020-04-08 at 20 16 11

@GuangchuangYu
Copy link
Member

try v >= 2.1.5 :)

@fionarhuang
Copy link
Contributor Author

fionarhuang commented Apr 9, 2020

It seems there is a new issue with the new version of geom_inset...

library(ape)
library(ggtree)
library(ggimage)
library(ggplot2)

set.seed(1)
tr <- rtree(50)
fig1 <- ggtree(tr, branch.length = "none")
fig1

n <- c(8, 10, 5, 6)
df_list <- lapply(n, FUN = function(x) {
    data.frame(node  = sample(1:99, size = x),
               A = sample(0:1, size = x, replace = TRUE),
               B = sample(0:1, size = x, replace = TRUE),
               C = sample(0:1, size = x, replace = TRUE))
})

i <- 1
pies_i <- nodepie(data = df_list[[i]], cols = 2:4, 
                  color = c("red", "blue", "black"))

# fig1 +
#     geom_point2(aes(subset = node %in% 60))
fig1 <- fig1 %>% collapse(node = 60)
fig1 +
    geom_inset(pies_i, width = 0.08, height =  0.08)+
    geom_point2(aes(subset = node %in% 60))

Below is the error I got

Error in grid.Call.graphics(C_setviewport, vp, TRUE) : 
  non-finite location and/or size for viewport
In addition: There were 32 warnings (use warnings() to see them)

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

2 participants