We have this simple data frame:
data <- data.frame(ID = rep(c("a","b"), each = 500),
time = 1:500,
val = rnorm(1000, mean=1, sd = 0.3))
We have data for 2 individuals (ID
== a
and b
). We want to subset the data for individual b
and make a scatterplot of val
vs data_point
using dplyr
and ggplot2
:
library(ggplot2)
library(dplyr)
data%>%
filter(ID == "b")%>%
mutate(data_point = c(1:500))%>%
ggplot(.,)+
geom_point(aes(x=data_point, y=val), size = 0.5)
Now say we want to make a single data point (say the very first data point/row) larger than the rest, and a different color. How can we do that from inside this pipe, without having to make an object outside of the pipe?