Search code examples
rplotdata-sciencehistogramp-value

Histogram plot for p-value


I want to plot the p-values pv.scf. Why doesn't my histogram reflect my 4 p-values?

> dput(pv.scf)
c(`211124_s_at` = 0.0003175435117273, `207029_at` = 0.00882067488788698, 
`216974_at` = 0.586375149259342, `226534_at` = 0.651991817084333
)

# Plot the sorted raw P-values
png("SCF_Raw_PvaluePlot.png")
par(mfrow=c(1,2))
hist(pv.scf, cex=0.9, col=c("#c1a87d", "#7ef9ff", "#97b9ce", "#1f456e"), las=2, cex.axis=0.6, xlab="Probes", ylab="P-values", main="Raw P-values for KITLG gene\n")
names(c("211124_s_at", "207029_at", "216974_at", "226534_at"))
abline(v=.01,col=2,lwd=2)
hist(-log10(pv.scf), col=c("#c1a87d", "#7ef9ff", "#97b9ce", "#1f456e"), xlab="Probes", ylab="log10(p-values)", main="-log10(P-values) for KITLG gene between\nall groups", cex.main=0.9)
names(c("211124_s_at", "207029_at", "216974_at", "226534_at"))
abline(v= -log10(.01),col=2,lwd=2)
dev.off()

enter image description here


Solution

  • It really sounds like you want a barchart rather than a histgram. Not all plots with bars are created equal. Try this

    par(mfrow=c(1,2))
    barplot(
      pv.scf, 
      cex=0.9, 
      col=c("#c1a87d", "#7ef9ff", "#97b9ce", "#1f456e"), 
      las=2, cex.axis=0.6, 
      xlab="", ylab="P-values", 
      main="Raw P-values for KITLG gene\n",
      names =c("211124_s_at", "207029_at", "216974_at", "226534_at"))
    abline(v=.01,col=2,lwd=2)
    barplot(
      -log10(pv.scf), 
      col=c("#c1a87d", "#7ef9ff", "#97b9ce", "#1f456e"), 
      xlab="", ylab="log10(p-values)", 
      main="-log10(P-values) for KITLG gene between\nall groups", 
      cex.main=0.9,
      las=2,
      names =c("211124_s_at", "207029_at", "216974_at", "226534_at"))
    abline(v= -log10(.01),col=2,lwd=2)
    

    which results in bar chart rather than histogram