簡體   English   中英

在散點圖中用兩位數表示法繪制

[英]Plot with two-digit noation in scatter plot

代碼plot(1,1, pch = "13")用符號“1”而不是“13”繪制一個點。

即使我可以用符號“13”繪制一個點,但是該點會與符號為“1”和“3”的兩個點混淆。

因此,為了避免混淆,我想通過用圓圈包圍“13”來指定符號“13”不是“1”和“3”(例如)。 (或用相同的紅色着色。)

在此處輸入圖片說明

您可以使用text函數繪制字符串。 例如:

plot(1, 1, xlim=c(0,2), ylim=c(0,2), pch=1, cex=3)  
text(1, 1, "13")

在此處輸入圖片說明

由於text是矢量化的,您還可以執行以下操作:

with(mtcars, plot(hp, wt, type="n"))
with(mtcars, text(hp, wt, round(mpg), col="blue", cex=mpg/20))

在此處輸入圖片說明

或者,進行一些額外的工作:

library(tidyverse)

col.vec = c("4"="grey40", "6"="green3","8"="darkorange")
cols = recode(mtcars$cyl, !!!col.vec)

with(mtcars, plot(hp, wt, type="n"))
with(mtcars, text(hp, wt, round(mpg), col=cols, cex=mpg/20))
with(mtcars, legend(50,5.2, 
                    bty="n",
                    pch=c(15,15,15),
                    pt.cex=1.5,
                    col=col.vec,
                    title="Cylinders", title.col="grey20",
                    legend=sort(unique(cyl))))

在此處輸入圖片說明

暫無
暫無

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

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