Question: How do I modify default ggplot2 axis?
0
gravatar for jaqx008
21 months ago by
jaqx00870
jaqx00870 wrote:

Hello everyone I have an r script that I used sometime ago to make scattered plots. But The scattered plotes generated by the script adjusted according to the data i provided it. now I am trying to modify the R script to specific axis like x-axis min=-5, max=5. y-axis min=-5 max=5 see my script below thanks.

#!/usr/bin/env Rscript
library(ggplot2)
DE <- read.csv("Scored.txt", header = FALSE, sep = "\t")
DE[,2] <- log(DE[2], 2)
pdf("scatterplot.pdf")
ggplot(DE, aes(x = DE$V2, y = DE$V3, color = DE$V8, pch = DE$V7 > .05)) + geom_point(alpha = 1/2) + geom_rug(sides = "l") + theme_minimal() +
labs (x = "Log Mean Expression", y = "Log2 Fold Change", pch = "P-value > 0.5", color = "Category", size = 48)
dev.off()

How can I add the command to adjust the axis as specified above?

rna-seq deseq2 ggplot2 rscript • 734 views
ADD COMMENTlink modified 21 months ago by rjactonspsfcf120 • written 21 months ago by jaqx00870
2
gravatar for rjactonspsfcf
21 months ago by
rjactonspsfcf120
Southampton
rjactonspsfcf120 wrote:

just add limits

<plot object> + xlim(-5,5) + ylim(-5,5)

see: https://ggplot2.tidyverse.org/reference/lims.html

ADD COMMENTlink written 21 months ago by rjactonspsfcf120

Where in the code could this fit in? thanks Ive tried adding the limits but not sure were it should be cos I keep getting error messages from terminal

ADD REPLYlink written 21 months ago by jaqx00870
2

let

p -> ggplot(DE, aes(x = DE$V2, y = DE$V3, color = DE$V8, pch = DE$V7 > .05)) + geom_point(alpha = 1/2) + geom_rug(sides = "l") + theme_minimal() +
labs (x = "Log Mean Expression", y = "Log2 Fold Change", pch = "P-value > 0.5", color = "Category", size = 48)

Then the code will be

p + xlim(-5,5) + ylim(-5,5)

Please refer to as suggested by rjactonspsfcf

https://ggplot2.tidyverse.org/reference/lims.html

ADD REPLYlink modified 21 months ago • written 21 months ago by Medhat8.7k

Thanks Guys. It works now but without the p. I appreciate it. :)

ADD REPLYlink written 21 months ago by jaqx00870
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1068 users visited in the last hour