sajuukLyu / ggunchull

A ggplot extension for drawing smooth non-convex circles around a set of points.
GNU General Public License v3.0
14 stars 3 forks source link

ggsave the fig is blank #5

Open seqyuan opened 1 month ago

seqyuan commented 1 month ago
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 commented 1 month ago

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()
  2. 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.