[R] Color in stripchart

Rasmus Liland jr@| @end|ng |rom po@teo@no
Wed Mar 10 17:22:54 CET 2021

Hello there again,

Sorry, I missed that part in the middle 
about set.seed.  As per [1], you need to 
run stripchart again with the add 
argument set to TRUE, and slicing the df 
according to the color, like so

	years <- sample(x=seq(2011, 2018), size = 365*8, replace = TRUE)
	values <- sample(x=seq(0,100), size = 365*8, replace = TRUE)
	df <- data.frame(year = years, value = values)
	df$color <- 'black'
	df[df$value<33,]$color <- 'blue'
	df[df$value>66,]$color <- 'red'
	stripchart(value ~ year, pch=18, method='stack', data=df)
	for (color in unique(df$color)) {
	  stripchart(value ~ year, pch=18, method='stack', data=df[df$color==color,], col=color, add=TRUE)


[1] https://stackoverflow.com/questions/32833210/define-color-for-each-datapoint-in-a-stripchart-separately

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20210310/f42f0e5a/attachment.sig>

More information about the R-help mailing list