我正在学习R,并希望绘制一个大型数据帧(~55000行)的散点图。我正在使用scatterplot
中的car
:
library(car)
d=read.csv("patches.csv", header=T)
scatterplot(energy ~ homogenity | label, data=d,
ylab="energy", xlab="homogenity ",
main="Scatter Plot",
labels=row.names(d))
其中patches.csv
包含数据框(下方)
我想以不同的方式显示两个label
集。由于数据量很大,绘图非常密集,因此我得到了右下方的结果(主要是红色数据可见)。图像需要一段时间才能渲染,所以在隐藏在最终图表之前,我可以看到黑色标记数据(左下方)。
我可以控制R先用红色绘制数据,还是有更好的方法来实现我的目标?
以下是我的数据示例:
label,channel,x,y,contrast,energy,entropy,homogenity
1,21,460,76,0.991667,0.640399,0.421422,0.939831
1,22,460,76,0.0833333,0.62375,0.364379,0.969445
1,23,460,76,0.129167,0.422908,0.589938,0.935417
1,24,460,76,0,1,0,1
1,25,460,76,0,1,0,1
1,26,460,76,0.0875,0.789627,0.253649,0.967361
1,27,460,76,2.4,0.528516,0.700859,0.845558
1,28,460,76,0.120833,0.562066,0.392998,0.945139
1,29,460,76,0.0125,0.975234,0.0329461,0.99375
1,30,460,76,0,1,0,1
1,31,460,76,0.1625,0.384662,0.5859,0.929861
0,0,483,82,0.404167,0.309505,0.61573,0.947222
0,1,483,82,0.0166667,0.728559,0.221967,0.991667
0,2,483,82,0,1,0,1
0,3,483,82,0.416667,0.327083,0.644057,0.940972
0,4,483,82,0.0208333,0.919054,0.0940364,0.989583
0,5,483,82,0.416667,0.327083,0.644057,0.940972
0,6,483,82,0,1,0,1
0,7,483,82,0.0333333,0.794479,0.192471,0.983333
0,8,483,82,0,1,0,1
0,9,483,82,0,1,0,1
0,10,483,82,0.0208333,0.958984,0.0502502,0.989583
答案 0 :(得分:1)
如果您想更改着色的顺序,请将参数col=2:1
传递给scatterplot
,然后您将在黑色之前绘制红色。您可以使用alpha
包中的scales
函数使您的点半透明(它采用颜色矢量和Alpha值,使每种颜色的密度不同)。
## More data
d <- data.frame(homogeneity=(x=rnorm(10000, 0.85, sd=0.15)),
label=factor((lab=1:2)),
energy=rnorm(10000, lab^1.8*x^2-lab, sd=x))
library(car)
library(scales) # for alpha
opacity <- c(0.3, 0.1) # opacity for each color
col <- 1:2 # black then red
scatterplot(energy ~ homogeneity | label, data=d,
ylab="energy", xlab="homogenity ",
main=paste0(palette()[col], "(", opacity, ")", collapse=","),
col=alpha(col, opacity),
labels=row.names(d))
答案 1 :(得分:0)
与bunk用alpha说的相似,
如果你有很多分数,那么单个分数的实际识别就不再有意义了。相反,您可能想要表示密度。使用smoothScatter(x,y)
并使用通常的points(morex,morey)
覆盖突出显示的点。您显然知道如何使用点(与绘图相同的参数),因此您很容易实现,并且您需要的知识非常少。