横轴上的右名称
Right Name in Horizontal Axis
目标:
我想在箱线图的水平轴上使用月份名称 "January" 和 "February"。
问题:
我试着去做,但我失败了。将 "Month" 和 "Names" 作为横轴文本是不正确的。
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
这里是 mydata
的 dput
:
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)
的结果:
你可以这样做:
boxplot(df$Count~df$Month)
它将 return :
如果要先显示一月再显示二月,请执行:
df[,1]<-factor(df[,1],levels=c('January','February'))
boxplot(df$Count~df$Month)
或者只是:
boxplot(df$Count~df$Month,names=c('January','February'))
目标:
我想在箱线图的水平轴上使用月份名称 "January" 和 "February"。
问题:
我试着去做,但我失败了。将 "Month" 和 "Names" 作为横轴文本是不正确的。
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
这里是 mydata
的 dput
:
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)
的结果:
你可以这样做:
boxplot(df$Count~df$Month)
它将 return :
如果要先显示一月再显示二月,请执行:
df[,1]<-factor(df[,1],levels=c('January','February'))
boxplot(df$Count~df$Month)
或者只是:
boxplot(df$Count~df$Month,names=c('January','February'))