简体   繁体   中英

How do I plot 3 variables along the x-axis in R plot?

How do I label the x-axis as actual , knn , and pca and plot its respective values along the y-axis ?

dat.pca.knn <- rbind(actual, knn, pca) 

plot(c(1, ncol(dat)),range(dat.pca.knn),type="n",main="Profile plot of probeset 206054_at\nwith actual and imputed values of GSM146784_Normal",xlab="Actual vs imputed values",ylab="Expression Intensity",axes=F,col="red") 
axis(side=1,at=1:length(dat.pca.knn),labels=dimnames(dat.pca.knn)[[2]],cex.axis=0.4,col="1",las=2,tick=T) 
axis(side=2) 

for(i in 1:length(dat.pca.knn)) { 
  dat.y <- as.numeric(dat.pca.knn[i,]) 
  lines(c(1:ncol(dat.pca.knn)),dat.y,lwd=2,type="p",col="1") 
} 

阴谋

Data

dput(dat[1:2,])

structure(c(1942.1, 40.1, 2358.3, 58.2, 2465.2, 132.6, 2732.9, 
64.3, 1952.2, 66.1, 2048.3, 69, 2109, 109.7, 3005.1, 59.4, 2568.1, 
81.7, 2107.7, 100.8, 1940.2, 170.1, 2608.8, 186.7, 1837.2, 103.8, 
1559.2, 86.8, 2111.6, 86, 2641, 152.7, 1972.7, 124.8, 1737.2, 
115, 1636.1, 202.1, 2718.4, 257.3), .Dim = c(2L, 20L), .Dimnames = list(
    c("1007_s_at", "1053_at"), c("GSM146778_Normal", "GSM146780_Normal", 
    "GSM146782_Normal", "GSM146784_Normal", "GSM146786_Normal", 
    "GSM146789_Normal", "GSM146790_Normal", "GSM146792_Normal", 
    "GSM146794_Normal", "GSM146796_Normal", "GSM146779_Tumor", 
    "GSM146781_Tumor", "GSM146783_Tumor", "GSM146785_Tumor", 
    "GSM146787_Tumor", "GSM146788_Tumor", "GSM146791_Tumor", 
    "GSM146793_Tumor", "GSM146795_Tumor", "GSM146797_Tumor")))

dat.pca.knn

> print(dat.pca.knn)
            [,1]
actual  8385.300
knn     7559.533
pca    10418.002

you probably need a barplot if Understand you correctly.

# just to recreate your data
dat.pca.knn <- dplyr::tribble(
   ~actual,     ~knn,      ~pca,
  8385.300, 7559.533, 10418.002  
)

with(
  dat.pca.knn,
  barplot(height = c(actual, knn, pca), 
          names.arg = c("actual", "knn", "pca"))
)

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM