簡體   English   中英

如何更改ggplot2中圖例的背景顏色?

[英]How to change background colour of legend in ggplot2?

有誰知道如何更改ggplot2中點圖例的背景顏色。 我已經創建了下面的圖並想更改圖例上的白色背景? 有任何想法嗎?

在此處輸入圖片說明

您可以使用themelegend.key參數。 ?theme

legend.key :圖例鍵下方的背景( element_rect() ;繼承自rect

那是

theme(legend.key = element_rect(fill = "black"))

一個例子:

a <- seq(1:5)
b <- seq(1:5)
c <- seq(1:5)
d <- data.frame(a, b, c)
ggplot(data = d, aes(x = a, y = b, color = factor(c))) +
  geom_point() +
  theme(legend.key = element_rect(fill = "yellow"))

產生:

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM