简体   繁体   English

绘图颜色R不正确

[英]Incorrect Plot Color R

I am using the following code to generate a plot: 我正在使用以下代码来生成图:

library(plotrix)

dat_fn = "emptiness.csv"
storage_fn = "final/results/emptiness_values.png"
data <- read.csv(dat_fn, header = TRUE, sep = "\t")

png(storage_fn)
sizeplot(data$PercentEmpty, data$PercentUniform, col = data$QuestionType)
legend("topleft", legend = levels(data$QuestionType), pch = "o", col = 
unique(data$QuestionType))
dev.off()

I should be getting two black points in the bottom left, and one red in the top right. 我应该在左下角得到两个黑点,在右上角得到一个红点。 Instead, I am getting one black and one red in the bottom left, and one black in the top right. 取而代之的是,我在左下角得到一种黑色和一种红色,在右上角得到一种黑色。 (See graph below.) I am completely stumped - what could be going on here? (请参见下图。)我完全感到困惑-这里可能会发生什么? I double checked my data three times, the data is not the problem. 我对数据进行了三遍仔细的检查,数据不是问题。

Plot 情节

My data is: 我的数据是:

ColumnName  PercentEmpty    PercentUniform  QuestionType
D   0.0 5.155436407691911e-05   a
E   0.0 0.00030932618446151465  a
F   0.14146517502706604 0.09666443264422334 b

Thanks! 谢谢!

I think the processing sizeplot does ends up reordering some points. 我认为处理sizeplot确实会重新排序一些点。 You don't seem to be using sizeplot 's feature of automatically resizing points, so I'd recommend just using plot instead which works just fine. 您似乎并没有使用sizeplot的自动调整点大小的功能,因此我建议您仅使用plot即可。

If you do need sizeplot, here's a hacky work-around: 如果您确实需要sizeplot,可以采用以下解决方法:

with(data, plot(PercentEmpty, PercentUniform, type = "n"))
with(subset(data, QuestionType == "a"), sizeplot(PercentEmpty, PercentUniform, col = 1, add = TRUE))
with(subset(data, QuestionType == "b"), sizeplot(PercentEmpty, PercentUniform, col = 2, add = TRUE))

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM