0

在这里我有theme_light(),但在情节中我仍然有 x/y 轴和图例 + 网格。我想删除那些,只有我的浅色背景+情节'pic'。当我使用theme_void-> 时,它会删除图例,但背景是无效的。知道如何解决这个问题,所以我只有一个白色背景和我的情节吗?

pic <- ggplot(data = art_dat, mapping = aes(x = x, y = y, group = path_id,
                                                color = step_id)
              ) + 
  geom_path(
            size = .9,
            alpha = 1000, #transparency of the lines
            show.legend = FALSE
                        
            ) +
            coord_equal() + 
            theme_light() + 
            scale_color_scico(palette = "berlin")          

在此处输入图像描述

4

2 回答 2

1

编辑:在您发布图片时更新。您没有图例,因此您不需要删除它。您想删除轴线、刻度线、文本、标题和可能(?)面板网格线:

pic <- ggplot(data = art_dat, mapping = aes(x = x, y = y, group = path_id,
                                                color = step_id)
              ) + 
  geom_path(
            size = .9,
            alpha = 1000, #transparency of the lines
            show.legend = FALSE
                        
            ) +
            coord_equal() + 
            theme_light() + 
            scale_color_scico(palette = "berlin") +
                theme(
        axis.line = element_blank(), 
        axis.text = element_blank(),
        axis.ticks = element_blank(),
        axis.title = element_blank(),
        panel.grid.major = element_blank(), # optional - remove gridlines
        panel.grid.minor = element_blank() # optional - remove gridlines
    )
于 2022-01-18T12:16:35.867 回答
0

如果对主题空白进行一些调整,就可以摆脱图例。此外,您可以使用plot.background参数将图例设为白色。在下面的示例中,我将其设为红色以表明没有剩余边距等。有一排白色像素,但我不知道该怎么做。

library(ggplot2)

p <- ggplot(mpg, aes(displ, hwy, colour = cyl)) +
  geom_point()

p + theme_void() +
  theme(
    legend.position = "none",
    plot.background = element_rect(fill = "red", colour = NA)
  )

reprex 包(v2.0.1)于 2022-01-18 创建

于 2022-01-18T14:05:03.467 回答