0

我正在绘制人口中的工作分布,因此 x 轴是一个分类变量。我设法用类别名称标记了 x 轴,但它们与实际绘图不一致。我不确定使用什么语法来对齐。

数据和代码:

d<-structure(c(5L, 2L, 4L, 4L, 10L, 5L, 7L, 4L, 6L, 4L, 6L, 6L, 
7L, 7L, 3L, 4L, 5L, 6L, 7L, 12L, 11L, 12L, 7L, 1L, 12L, 6L, 12L, 
3L, 12L, 1L, 5L, 4L, 12L, 2L, 11L, 12L, 2L, 12L, 5L, 3L, 2L, 
1L, 1L, 2L, 3L, 4L, 4L, 7L, 10L, 12L, 5L, 6L, 5L, 5L, 11L, 11L, 
7L, 4L, 4L, 6L, 12L, 6L, 12L, 5L, 4L, 7L, 3L, 12L, 7L, 8L, 4L, 
2L, 3L, 3L, 4L, 4L, 5L, 5L, 7L, 3L, 7L, 2L, 5L, 6L, 7L, 4L, 5L, 
2L, 4L, 4L, 2L, 4L, 5L, 10L, 4L, 7L, 12L, 3L, 4L, 6L, 12L, 5L, 
4L, 2L, 4L, 4L, 12L, 1L, 3L, 4L, 5L, 4L, 7L, 4L, 4L, 3L, 1L, 
12L, 5L, 4L, 12L, 2L, 12L, 3L, 6L, 12L, 4L, 4L, 3L, 4L, 6L, 5L, 
12L, 2L, 5L, 7L, 4L, 7L, 7L, 4L, 6L, 6L, 4L, 7L, 6L, 6L, 12L, 
12L, 12L, 3L, 6L, 2L, 4L, 2L, 3L, 3L, 4L, 4L, 4L, 5L, 5L, 6L, 
6L, 12L, 12L, 4L, 3L, 12L, 12L, 6L, 2L, 4L, 2L, 7L, 2L, 2L, 4L, 
2L, 6L, 4L, 12L, 6L, 6L, 12L, 5L, 2L, 7L, 6L, 4L, 4L, 6L, 2L, 
1L, 2L, 6L, 7L, 2L, 6L, 1L, 2L, 8L, 12L, 12L, 5L, 2L, 4L, 3L, 
2L, 6L, 2L, 7L, 4L, 12L, 10L, 4L, 6L, 12L, 2L, 2L, 5L, 6L, 1L, 
3L, 4L, 4L, 5L, 8L, 4L, 5L, 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, 5L, 6L, 12L, 11L, 5L, 4L, 4L, 
1L, 7L, 4L, 2L, 4L, 11L, 4L, 4L, 4L, 11L, 5L, 2L, 6L, 11L, 3L, 
6L, 10L, 12L, 12L, 4L, 6L, 2L, 6L, 3L, 6L, 7L, 7L, 11L, 7L, 11L, 
6L, 12L, 7L, 2L, 6L, 5L, 8L, 4L, 4L, 11L, 10L, 12L, 7L, 6L, 4L, 
4L, 2L, 12L, 2L, 12L, 12L, 4L, 9L, 11L, 2L, 11L, 11L, 4L, 7L, 
2L, 1L, 4L, 4L, 7L, 12L, 12L, 3L, 4L, 1L, 4L, 4L, 6L, 6L, 4L, 
2L, 7L, 12L, 7L, 5L, 2L, 12L, 1L, 2L, 3L, 5L, 6L, 5L, 5L, 5L, 
6L, 7L, 7L, 2L, 8L, 5L, 5L, 4L, 8L, 6L, 5L, 5L, 4L, 2L, 4L, 4L, 
5L, 5L, 10L, 11L, 2L, 6L, 12L, 3L, 7L, 5L, 12L, 5L, 5L, 6L, 6L, 
2L, 11L, 8L, 4L, 2L, 7L, 5L, 2L, 4L, 5L, 5L, 7L, 5L, 2L, 6L, 
2L, 3L, 6L, 4L, 9L, 6L, 1L, 4L, 6L, 6L, 2L, 4L, 7L, 5L, 2L, 12L, 
4L, 3L, 7L, 2L, 11L, 5L, 4L, 5L, 5L, 11L, 12L, 7L, 4L, 12L, 10L, 
6L, 5L, 12L, 7L, 4L, 5L, 5L, 11L, 2L, 11L, 2L, 2L, 7L, 12L, 7L, 
12L, 3L, 4L, 2L, 5L, 4L, 2L, 3L, 4L, 5L, 10L, 7L, 9L, 11L, 2L, 
2L, 11L, 5L, 8L, 7L, 11L, 10L, 4L, 4L, 2L, 4L, 5L, 5L), .Label = c("Construction", 
"Education or healthcare", "Finance", "Government/Military", 
"Legal or business", "Leisure and hospitality", "Manufacturing", 
"Media and telecommunications", "Mining and logging", "Transport and utilities", 
"Unemployed", "Wholesale or retail"), class = "factor")

#d

Occs<-c("Legal or business", "Education or healthcare", "Government/Military", "Transport and utilities", "Manufacturing", "Leisure and hospitality", "Finance", "Wholesale or retail", "Unemployed", "Construction", "Media and telecommunications", "Mining and logging")
#print(Occs)

#plot(d$Occupation)
plot(d, xaxt="n")
axis(side=1, at=1:12, labels=Occs, las=3, cex.axis=1) #, cex.axis=0.35
4

1 回答 1

1

d是一个因素,这意味着通过有点迷宫的 S3 方法为plot您调度最终plot.factor会调用barplot(table(d)). 方便地barplot返回条形中点的值:

p <- plot(d, xaxt="n")
axis(side=1, at=p, labels=Occs, las=3, cex.axis=1) #, cex.axis=0.35
于 2013-11-07T23:49:35.783 回答