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

ggsave the fig is blank #5

Open
seqyuan opened this issue Jul 22, 2024 · 1 comment
Open

ggsave the fig is blank #5

seqyuan opened this issue Jul 22, 2024 · 1 comment

Comments

@seqyuan
Copy link

seqyuan commented Jul 22, 2024

library(ggplot2)
library(ggunchull)

data("pancExample")
plotData <- pancExample

#### setup a proper distance to extend (and simplify) the circle (here use 3% of the range of x axis)
delta_r <- 0.03
th_r <- 0.03
delta <- diff(range(plotData$UMAP_1)) * delta_r
th <- diff(range(plotData$UMAP_1)) * th_r

p<- ggplot(plotData, aes(x = UMAP_1, y = UMAP_2)) +
  geom_point(aes(color = celltype), size = 0.3, shape = 16) +
  stat_unchull(aes(color = celltype, fill = celltype), alpha = 0.3, n = 5, delta = delta, th = th) +
  theme(
    aspect.ratio = 1,
    panel.background = element_blank(),
    panel.grid = element_blank(),
    axis.line = element_line()
  )

p

ggsave("aaa.pdf", p, w=5,h=5)

the aaa.pdf is blank

@sajuukLyu
Copy link
Owner

Sorry for being late replying. It may be a bug caused by the incompatibility between graphics::xspline and ggplot system. Some other packages also met similar problems, such as hrbrmstr/ggalt#70.

There are two ways to avoid this:

  1. save graph with R basic way
pdf("aaa.pdf", w=5, h=5)
p
dev.off()
  1. run dev.off() before ggsave
p
dev.off()
ggsave("aaa.pdf", w=5, h=5)

These both work for me, hope these can solve your problem.

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