2015-11-19 33 views
-1

目標:
我想在boxplot的橫軸上設置月份名稱「January」和「February」。水平軸的正確名稱

問題:
我試圖做到這一點,但我失敗了。將「月」和「名稱」作爲橫軸上的文本是不正確的。

mydata 

#  Month Count 
# 1 January 10 
# 2 January 11 
# 3 January 22 
# 4 January 55 
# 5 January  4 
# 6 January 88 
# 7 February 44 
# 8 February 40 
# 9 February 30 
# 10 February 28 

這裏是dputmydata的:

mydata<-structure(list(Month = structure(c(2L, 2L, 2L, 2L, 2L, 2L, 1L, 
1L, 1L, 1L), .Label = c("February", "January"), class = "factor"), 
    Count = c(10, 11, 22, 55, 4, 88, 44, 40, 30, 28)), .Names = c("Month", 
"Count"), row.names = c(NA, -10L), class = "data.frame") 

這裏是boxplot(mydata)結果:

enter image description here

+0

你箱線圖是正確的,在我看來t表示'Month'和'Count'的分佈。這是完全錯誤的,因爲你的目標是顯示'January'和'February'。這不是蜱名稱的問題。 –

+0

這是真的,這就是爲什麼我需要一些支持。 –

回答

0

你可以這樣做:

boxplot(df$Count~df$Month) 

則回覆:

enter image description here

如果你想顯示一月然後二月,這樣做:

df[,1]<-factor(df[,1],levels=c('January','February')) 
boxplot(df$Count~df$Month) 

或者只是:

boxplot(df$Count~df$Month,names=c('January','February')) 

enter image description here

+0

謝謝你的幫助!橫軸是否可以從1月開始,然後是2月? –

+0

是的,我編輯了答案 – etienne