I have a dataframe:
test <- structure(list(Sample_ID = c("S1","S2", "S3", "S4", "S1", "S2", "S3", "S4"),
CN_Region = c("A", "A", "A", "A", "B", "B", "B", "B"),
MedianLog2Ratio = c(-0.2, -0.2, -0.25, -0.25, -0.25, -0.2, -0.1, -0.3),
CN_truth = c("2", "2", "2", NA, "2", "2", "2", "1")), class = c("data.table","data.frame"))
When I plot hist
it works fine:
hist(test$MedianLog2Ratio)
I would like to plot a per region histogram using ggplot and overlay with geom_points
CN_truth
associated with the SampleID
:
g <- ggplot(test, aes(x = MedianLog2Ratio)) + geom_histogram()
g + geom_point(aes(colour = factor(CN_truth))
Plot should look like this loosely (of course it will have fewer bins with lesser data):
where legend refers to CN_truth
and title is CN_Region