簡體   English   中英

R制作圖

[英]R Making barplot

我正在嘗試使用以下數據進行繪制

      Dept
Admit        A   B   C   D   E   F
Admitted    601 370 322 269 147  46
Rejected    332 215 596 523 437 668

並且我嘗試了以下代碼:

admission_department <- barplot(biasUCB_d, main="Admit by deparment",
                                xlab="biasUCB_d[['Dept']]", 
                                col=c("darkblue","red"),
                                legend = rownames(biasUCB_d[['Dept']]), 
                                beside=TRUE)

用於創建數據集的編碼名稱為:

biasUCB_d <- margin.table(UCBAdmissions, c(1,3)) 

我究竟做錯了什么?

假設Dept是列表的元素,則它應該起作用:

數據:

biasUCB_d <- list(Dept = read.table(header=T, text='
Admit        A   B   C   D   E   F
Admitted    601 370 322 269 147  46
Rejected    332 215 596 523 437 668'))

解:

dmission_department <- barplot(as.matrix(biasUCB_d$Dept[2:7]), main="Admit by deparment",
                               xlab="biasUCB_d[['Dept']]", 
                               col=c("darkblue","red"),
                               legend = biasUCB_d$Dept$Admit, 
                               beside=TRUE)

輸出:

在此處輸入圖片說明

嘗試:

admission_department <- barplot(biasUCB_d, main="Admit by deparment",
                                xlab="Department", 
                                col=c("darkblue","red"),
                                legend.text = rownames(biasUCB_d), 
                                beside=TRUE)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM