How to reduce the spacing between lines and points in R "both" types

I tried to build a series of points in R, and I use type="b" as a plot option. However, there are many gaps (spaces) between points and lines between them, so much so that the line completely disappears between some points. She is a picture of how she looks:

disappearing lines example

I tried to make the points smaller with the cex plot option, but this does not help, since it only changes the size of the points, and not where the lines between the points between them start and end. I do not know if this matters, but the characters I use are pch=1 .

I am interested to know if this supplement can be reduced and how you do it. I'm not interested in using type=o as an option for plotting.

+6
source share
2 answers

Using a data frame with the name dfs seems to create a mechanism for setting the surrounding “white halo” to whatever size you want, adjusting the “cex” values ​​for white and black points:

 plot(y~x,data=dfs, type="l") with(dfs, points(x,y, pch=16,col="white",cex=1.4)) with(dfs, points(x,y,cex=1) ) 
+3
source

Any specific reason you don't want to use type="o" ? This is the easiest way to get the desired effect:

 # Fake data set.seed(10) dfs = data.frame(x=1:10, y=rnorm(10)) plot(y~x,data=dfs, type="o", pch=21, bg='white') 

pch=21 is a circle marker, such as pch=1 , but with a border and padding. We set the fill to white using bg="white" to "cover" the lines passing through the point markers.

enter image description here

You can also use cex to resize the marker to avoid matching and make visible the lines between adjacent points:

 set.seed(10) dfs = data.frame(x=1:100, y=cumsum(rnorm(100))) plot(y~x,data=dfs, type="o", pch=21, bg="white", cex=0.6) 

enter image description here

+4
source

All Articles