<\/script>')

How to add lines between points without "touching" points, for example, in "type = 'b"?

I would like to add lines between the points in the graph in R. But not between them.

Therefore, I use "strings". But I would like to keep the style "type = 'b", while the line stops immediately before the point.

+3
source share
3 answers

If ggplot is your thing, give it a whirl. ggplot does not support type = "b"as basic graphics. We can get around this, though with some rework and a subset:

library(ggplot2)
x <- seq(1, pi, pi/36)
y <- sin(x)
z <- data.frame(x,y)



ggplot(z, aes(x,y)) + 
    geom_line(data = subset(z, x > 1.5 & x < 2.5)) + 
    geom_point(size = 6, colour = "white") +
    geom_point(size = 3, colour = "black") +
    theme_bw()

enter image description here

+9
source

Set some data

x <- seq(1, pi, pi/36)
y <- sin(x)

Create a plot with all the points

plot(x, y)

Add lines type="b"for some points:

lines(x[10:20], y[10:20], type="b")

enter image description here

+5
source

lines = 'c', . , .

0

All Articles