Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201894

plot geom_point on top of geom_histogram

$
0
0

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_pointsCN_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): sample_plot where legend refers to CN_truth and title is CN_Region


Viewing all articles
Browse latest Browse all 201894

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>