Как избавиться от яркой границы вокруг сюжета в прозрачном режиме `theme_bw`? - PullRequest
0 голосов
/ 29 мая 2018

Есть ли способ избавиться от этих белых линий в theme_bw() при печати прозрачным на более темном фоне?В theme_minimal() они не появляются, но я хочу theme_bw().Я попытался изменить несколько вариантов theme(), но безуспешно.

Пример:

data(iris)
names(iris) <- tolower(names(iris))

library(ggplot2)
plot1 <- ggplot(iris, aes(x=sepal.length, y=sepal.width)) +
  geom_smooth() +
  theme_bw() + 
  theme(rect=element_rect(fill="transparent"),
        panel.grid = element_blank(),
        panel.background= element_blank())
pdf("plot1.pdf", width=4, height=4)
plot1
dev.off()

plot2 <- ggplot(iris, aes(x=sepal.length, y=sepal.width)) +
  geom_smooth() +
  theme_minimal() + 
  theme(rect=element_rect(fill="transparent"),
        panel.grid = element_blank(),
        panel.background= element_blank())
pdf("plot2.pdf", width=4, height=4)
plot2
dev.off()

enter image description here

Примечание: Я делаю это в InDesign CS4.

Ответы [ 3 ]

0 голосов
/ 29 мая 2018

Почему бы не использовать theme_minimal и адаптировать тему?

col = "#383838"
plot2 <- ggplot(iris, aes(x=sepal.length, y=sepal.width)) +
  geom_smooth() +
  theme_minimal() + 
  theme(rect=element_rect(fill="transparent"),
        panel.grid = element_blank(),
        axis.ticks = element_line(colour = col),
        axis.line = element_line(colour = col, color = col, size = 0.1),
        panel.border = element_rect(colour = col),
        panel.background= element_blank())
pdf("plot2.pdf", width=4, height=4)
plot2
dev.off()

Или вам по какой-то причине нужно использовать theme_bw?

0 голосов
/ 30 мая 2018

Вы ищете элемент темы plot.background, а не panel.background.График представляет собой всю область, включая внешние оси, в то время как панель представляет собой область внутри или между осями.

Уродливые графики, иллюстрирующие разницу:

ggplot(iris, aes(x=sepal.length, y=sepal.width)) +
  geom_smooth() +
  theme_bw() + 
  theme(rect=element_rect(fill="transparent"),
        panel.grid = element_blank(),
        panel.background= element_rect(color = "red", fill = "yellow", size = 6))

ggplot(iris, aes(x=sepal.length, y=sepal.width)) +
  geom_smooth() +
  theme_bw() + 
  theme(rect=element_rect(fill="transparent"),
        panel.grid = element_blank(),
        plot.background = element_rect(color = "red", fill = "yellow", size = 6))

theme_bw по умолчанию - фон графика с белой рамкой.

theme_bw()$plot.background
List of 5
 $ fill         : NULL
 $ colour       : chr "white"
 $ size         : NULL
 $ linetype     : NULL
 $ inherit.blank: logi TRUE
 - attr(*, "class")= chr [1:2] "element_rect" "element"

Поэтому вместо plot.background можно установить element_blank или element_rect с цветом NA или прозрачным, или любым другим способом сделать его невидимым.Поскольку вам не нужны никакие атрибуты фона графика, самый простой - это просто plot.background = element_blank().

ggplot(iris, aes(x=sepal.length, y=sepal.width)) +
  geom_smooth() +
  theme_bw() + 
  theme(rect=element_rect(fill="transparent"),
        panel.grid = element_blank(),
        plot.background = element_blank())
0 голосов
/ 29 мая 2018

Панель Граница должна делать трюк

plot1 <- ggplot(iris, aes(x=sepal.length, y=sepal.width)) +
  geom_smooth() +
  theme_bw() + 
  theme(rect=element_rect(fill="transparent"),panel.border = element_blank(),
        panel.grid = element_blank(),
        panel.background= element_blank())
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...