I am trying to plot a vector field, with some vectors set invisible, using this code:
library(cowplot)
size <- 1/12
strength <- 8
centerx <- 0
centery <- -12
diagsize <- 200
x <- rep(1:diagsize - diagsize/2, times = diagsize)
y <- rep(1:diagsize - diagsize/2, each = diagsize)
xend <- numeric()
yend <- numeric()
distance <- numeric()
replace_factor_01 <- numeric()
replace_factor <- numeric()
h <- numeric()
for (i in 1:(diagsize*diagsize)){ #
distance[i] <- sqrt((x[i]-centerx)^2+(y[i]-centery)^2) # simply get absolute distance of each pixel to lens center
replace_factor_01[i] <- 0 # this will be color intensity
replace_factor[i] <- 0 # wheras this will be arrow length
h[i] <- 0 # this will be color (0 = red, 0.667 = blue)
if (distance[i] < 2*3.141592/size){replace_factor_01[i] <- sin(distance[i]*size)} # if within range, compute distortion as value -1..1
replace_factor[i] <- replace_factor_01[i]*strength # linearly stretch
if (replace_factor[i] < 0){h[i] <- 0.667} # set color
xend[i] <- x[i] + (x[i]-centerx)/distance[i]*replace_factor[i] # compute distortion vector
yend[i] <- y[i] + (y[i]-centery)/distance[i]*replace_factor[i]
if ((x[i] %% 5) !=0 | (y[i] %% 5) != 0) {replace_factor_01[i] <- 0} # only set some arrows visible
}
data <- data.frame(x,y,distance, h, replace_factor_01,replace_factor,xend,yend)
p <- ggplot(data,aes(x,y))+
geom_segment(aes(xend=xend,yend=yend),col=hsv(h,abs(replace_factor_01),1))
#geom_segment(aes(xend=xend,yend=yend),col=hsv(h,abs(replace_factor_01),1), size=5)
print(p)
The result looks like this:
When I use"size = 5", the lines don't merely become thicker, but look like this:
What am I getting wrong?