如何避免使用基本图的重叠绘图(对于点)? [英] How to avoid overplotting (for points) using base-graph?
问题描述
我正在完成一篇论文的图表,并决定(
这个函数现在可以作为 raw.means.plot
和 raw.means.plot2
在 plotrix
package(在CRAN上)。
标准方法是在绘图之前向数据添加一些噪音。 R有一个函数jitter(),它的确如此。您可以使用它将必要的噪音添加到您的情节中的坐标。例如:
X < - rep(1:10,10)
Z < - as.factor( (字母[1:10],100,替换= T))
plot $ b轴(1,at = 1:10,labels = levels(Z))
I am in my way of finishing the graphs for a paper and decided (after a discussion on stats.stackoverflow), in order to transmit as much information as possible, to create the following graph that present both in the foreground the means and in the background the raw data:
However, one problem remains and that is overplotting. For example, the marked point looks like it reflects one data point, but in fact 5 data points exists with the same value at that place.
Therefore, I would like to know if there is a way to deal with overplotting in base graph
using points
as the function.
It would be ideal if e.g., the respective points get darker, or thicker or,...
Manually doing it is not an option (too many graphs and points like this). Furthermore, ggplot2
is also not what I want to learn to deal with this single problem (one reason is that I tend to like dual-axes what is not supprted in ggplot2
).
Update: I wrote a function which automatically creates the above graphs and avoids overplotting by adding vertical or horizontal jitter (or both): check it out!
This function is now available as raw.means.plot
and raw.means.plot2
in the plotrix
package (on CRAN).
Standard approach is to add some noise to the data before plotting. R has a function jitter() which does exactly that. You could use it to add the necessary noise to the coordinates in your plot. eg:
X <- rep(1:10,10)
Z <- as.factor(sample(letters[1:10],100,replace=T))
plot(jitter(as.numeric(Z),factor=0.2),X,xaxt="n")
axis(1,at=1:10,labels=levels(Z))
这篇关于如何避免使用基本图的重叠绘图(对于点)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!