grep - Conditional Merge in R Data Frame using a String as a search -
i prepping database plotting in ggplot
plot large geom_point()
plot. 1 set of point stand out , thinking of making dummy column use column color variable in:
p <- ggplot(data, aes(x-x,y-y,color=color) colors=c("yes"="orange2", "no"="grey") scale_color_manual(values=colors)
to make dummy column wanted follows:
df$color <- "no"
to set default color, , use grep substitute make highlight color.
df$color[grep("string", df$v1, ignore.case=t),] < "yes"
where v1
column contains string substitute. although love suggestions on how substitution interested in learning more direct coloring method involve highlighting data of particular value.
thanks
here 1 way using grepl
. using mtcars
data set illustrative purposes. want merc
stand out. can call
ggplot(mtcars, aes(mpg, hp)) + geom_point(aes(colour = grepl('merc', rownames(mtcars)))) + scale_colour_manual("merc", values = c('black', 'red'))
Comments
Post a Comment