如何告诉R在散点图上用颜色填充圆点?

时间:2013-12-08 14:57:28

标签: r

我想用颜色填充散点图上的实心圆点。 我试过这个:

>  plot(dframe1$TV~dframe1$Books)
>  xlab="Number of books read per month"
>  plot(dframe1$TV~dframe1$Books,
          xlab="Number of books read per month")
> plot(dframe1$TV~dframe1$Books,
         xlab="Number of books read per month",
         ylab="Hours of TV watched per week",
         main="Associations between time spent watching TV and reading",
         col.main="red",
         cex=1.5,
         pch=21,
         bg=”light green”)
 Error: unexpected input in:
"pch=21,bg=”"

它不起作用。 我很感激建议/帮助。 :)

2 个答案:

答案 0 :(得分:9)

颜色名称不含空格,请尝试使用"lightgreen"

实施例

set.seed(1) # some random data
x <- rnorm(20, 5)
y <- 2 + .78*x + rnorm(20)
plot(y~x, pch=21,  bg="lightgreen")

产生:

enter image description here

答案 1 :(得分:-1)

plot(data,col=brewer.pal(3,"Set1"),pch = 15,cex = 1.1 )

Plot With Filled Points