使用ggplot2包中的qplot函数进行单变量分析

时间:2017-12-26 15:38:28

标签: r ggplot2

X <- round(quantile(Retaildata$monthly_salary.x,c(.90,.92,.94,.96,.98,1)),0)
Y <- c('P90','P92','P94','P96','P98','P100')
library(ggplot2)
qplot(x=Y,y=X,label=X,geom = c('text','point'), hjust = -.25)

为什么P100显示在最左侧? 我怎么把它带到最后,即向右?

qplot_graph

1 个答案:

答案 0 :(得分:1)

试试这个:

set.seed(1)
X <- round(quantile(abs(rnorm(1000))*12500,c(.90,.92,.94,.96,.98,1)),0)
Y <- c('P90','P92','P94','P96','P98','P100')

# 'mixedsort' orders character strings containing embedded numbers so that 
# the numbers are numerically sorted rather than sorted by character value 
library(gtools)
Y <- factor(Y, levels=mixedsort(Y))

library(ggplot2)
qplot(x=Y,y=X,label=X,geom = c('text','point'), hjust = -.25)

enter image description here