簡體   English   中英

如何在R中使用漸變顏色和形狀在散點圖的點周圍放置邊框?

[英]How to Place a border around points for the scatter plot with gradient color and shape in R?

我的目標是在scatter plot中將點周圍放置邊界,WHICH具有基於值的漸變顏色漸變形狀 (如下面的腳本所示)。

ggplot(filname, aes(Va1, Var2, col= PR, size=PR)) +
  geom_point() +
  labs(list(title = "Title", y = "Var2", x = "Var1")) +
  xlim(0, 150) +
  scale_color_gradientn(colours = rainbow(7)) +
  scale_x_continuous(breaks=seq(0, 150, 12))

** PR is the third Var in my data. 

生成的情節 在此處輸入圖片說明

我在這里發現以下問題:

但實際上,由於我在上面加粗了兩個原因,它們在我的情況下不起作用,我想保留漸變顏色漸變形狀,但同時在點周圍添加邊框以使其更明顯。

基本上,要在ggplot中制作輪廓顏色,我們會發現:

  1. 邊框顏色

當我采取以下行動時考慮到這一點

ggplot(PR_Grt100_REL_80, aes(Age, SC, col= PR, size=PR)) + 
  geom_point(aes (fill= PR), colour = "black") +
  labs(list(title = "Title", y = "Var2", x = "Var1")) +
  xlim(0, 150) +
  scale_color_gradientn(colours = rainbow(7)) +
  scale_x_continuous(breaks=seq(0, 150, 12))

我將得到以下圖表!

在此處輸入圖片說明

任何幫助都受到高度贊賞?

我認為您需要做的就是使用尊重fillcolor的形狀。 形狀21:25具有此屬性, http://sape.inf.usi.ch/quick-reference/ggplot2/shape

使用mtcars

library(ggplot2)
ggplot(mtcars, aes(mpg, hp, fill = cyl, size = cyl)) +
    geom_point(shape = 21, stroke = 2) + # change the thickness of the boarder with stroke
    scale_fill_gradientn(colours = rainbow(7)) +
    scale_size(range = c(2,6)) # only for example visibility

在此處輸入圖片說明

暫無
暫無

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

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