水平轴中的正确名称

时间:2015-11-19 07:38:35

标签: r statistics boxplot

目标:
我希望在箱形图的横轴上有月份名称“1月”和“2月”。

问题:
我试着这样做,但我失败了。将“月”和“名称”作为横轴的文本是不正确的。

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

以下是dput的{​​{1}}:

mydata

以下是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") 的结果:

enter image description here

1 个答案:

答案 0 :(得分:0)

你可以这样做:

boxplot(df$Count~df$Month)

它将返回:

enter image description here

如果要显示1月和2月,请执行:

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