在R中为x轴离散数据添加更多间距

时间:2013-03-09 21:49:41

标签: r statistics ggplot2

enter image description here

正如您所看到的,X轴上每个项目之间的间距非常小。有没有办法增加它?

合并数据框(https://dl.dropbox.com/u/81597211/Untitled.pdf

row.names   LCA_CASE_WORKLOC1_CITY  LCA_CASE_JOB_TITLE  LCA_CASE_WORKLOC1_STATE LCA_CASE_WAGE_RATE_FROM Company
    4726    REDWOOD SHORES  SOFTWARE DEVELOPER - ARCHITECT  CA  263500.00   ORACLE
    102663  DENVER  SOFTWARE ENGINEER (SOFTWARE DEVELOPER 5)    CO  170000.00   ORACLE
    103621  DENVER  SOFTWARE ENGINEER (SOFTWARE DEVELOPER 5)    CO  170000.00   ORACLE
    95210   SANTA CLARA SOFTWARE ENGINEER (SOFTWARE DEVELOPER 4)    CA  155000.00   ORACLE
    18858   SANTA CLARA SOFTWARE ENGINEER (CONSULTING SOLUTION DIRECTOR)    CA  150000.00   ORACLE
    19514   IRVING  CONSULTING TECHNICAL MANAGER    TX  150000.00   ORACLE
    57054   REDWOOD SHORES  SOFTWARE ENGINEER (SOFTWARE DEVELOPER 4)    CA  150000.00   ORACLE
    76335   REDWOOD SHORES  SOFTWARE ENGINEER (APPLICATIONS DEVELOPER 4)    CA  150000.00   ORACLE
    79964   REDWOOD SHORES  SOFTWARE ENGINEER (SOFTWARE DEVELOPER 5)    CA  150000.00   ORACLE

代码

colour = factor(merged$Company)
xcolor = factor(merged$LCA_CASE_WORKLOC1_STATE)
qplot(merged[[2]], merged[[4]], colour = colour, xlab="Positions", ylab ="Salary", main="H1B Salary 2012") + theme(axis.text.x=element_text(angle=90,vjust=0.5, hjust=1, size=10, color= xcolor, lineheight=10)) + scale_y_continuous(breaks=seq(0,300000, 10000)) + theme(panel.grid.minor = element_line(colour = "red", linetype = "dotted")) + scale_x_discrete(merged[[2]])

1 个答案:

答案 0 :(得分:0)

为了提高标签的可读性,您可以通过添加+ coord_flip() see here.

来切换轴

您可以做的第二件事是(在添加+coord_flip()之后)在导出绘图时调整高度和宽度并将其打印在A3纸上。例如,使用ggsave