ggplot2 easyplot①

img_87791e5e4eaa4a710cbda687b12f9aa5.png

ggplot2.stripchart:使用ggplot2和R软件的简单一维散点图

介绍

ggplot2.stripchart是一个易于使用的函数(来自easyGgplot2包),使用ggplot2绘图系统和R软件生成条带图。 条形图也被称为一维散点图(或点图)。 当样本量较小时,这些图比较适用于箱型图。

加载数据

# library(devtools)
# install_github("easyGgplot2", "kassambara")
library(easyGgplot2)
# create a numeric vector
numVector<-rnorm(100)
head(numVector)
# data.frame
df <- ToothGrowth
head(df)
  len supp dose
1  4.2   VC  0.5
2 11.5   VC  0.5
3  7.3   VC  0.5
4  5.8   VC  0.5
5  6.4   VC  0.5
6 10.0   VC  0.5

ToothGrowth描述了维生素C对豚鼠牙齿生长的影响。有3个变量有60个观测值。 * [,1] len数字牙齿长度。 * [,2]补充因子补充类型(VC或OJ)。 * [,3]剂量数字以毫克为单位的剂量。

# Stripchart from a single numeric vector 
ggplot2.stripchart(data=numVector)
# Basic stripchart from the vector "len"
ggplot2.stripchart(data=df, xName='dose',yName='len')
#change dot size
ggplot2.stripchart(data=df, xName='dose',yName='len', 
                   size=3)
# Change the orientation: Horizontal stripchart
ggplot2.stripchart(data=df, xName='dose',yName='len',
                   orientation="horizontal")
# Stripchart with box plot
ggplot2.stripchart(data=df, xName='dose',yName='len',
                   addBoxplot=TRUE)
# stripchart with notched box plot
ggplot2.stripchart(data=df, xName='dose',yName='len',
                   addBoxplot=TRUE,notch=TRUE)
img_64471296d829719048323bd3eee3cf6f.png

notch:如果为真,则制作缺口盒图。 缺口显示中间值周围的置信区间.缺口用于比较组; 如果两个盒子的缺口不重叠,这是有力的证据表明两组中位数不同。

带平均点的带状图


# Stripchart with mean point
ggplot2.stripchart(data=df, xName='dose',yName='len',
                   addMean=TRUE, meanPointShape=23, meanPointSize=4,
                   meanPointColor="black", meanPointFill="blue")
# Change the stripchart color
ggplot2.stripchart(data=df, xName='dose',yName='len',
                   colour="red")

img_35e102ec552e68b80641f773071ce1c5.png

更改条形图点的形状

# Change point shape
ggplot2.stripchart(data=df, xName='dose',yName='len',
                   shape=18)
# Change point shape
ggplot2.stripchart(data=df, xName='dose',yName='len',
                   shape=17)
img_e9d045dde73e753c93b47a8a28567ea4.png

主要参数

更多信息:


img_47cf93afd35c1a4b3cfe08a94617e7a8.png

主标题和坐标轴标签



# Change main title and axis titles
ggplot2.stripchart(data=df, xName='dose',yName='len',
                   mainTitle="Plot of length \n by dose",
                   xtitle="Dose (mg)", ytitle="Length")
# Customize title styles. Possible values for the font style :
# 'plain', 'italic', 'bold', 'bold.italic'.
ggplot2.stripchart(data=df, xName='dose',yName='len',
                   xtitle="Dose (mg)", ytitle="Length",
                   mainTitle="Plot of length \n by dose",
                   mainTitleFont=c(14,"bold.italic", "red"),
                   xtitleFont=c(14,"bold", "#993333"),
                   ytitleFont=c(14,"bold", "#993333"))
# Hide x an y axis titles
ggplot2.stripchart(data=df, xName='dose',yName='len',
                   xShowTitle=FALSE, yShowTitle=FALSE)
img_d0128cc8364735800501d8988e2f5e4d.png

坐标轴




# Axis ticks labels and orientaion
ggplot2.stripchart(data=df, xName='dose',yName='len',
                   xShowTitle=FALSE, yShowTitle=FALSE,
                   xTickLabelFont=c(14,"bold", "#993333"),
                   yTickLabelFont=c(14,"bold", "#993333"),
                   xtickLabelRotation=45, ytickLabelRotation=45)
# Hide axis tick labels
ggplot2.stripchart(data=df, xName='dose',yName='len',
                   xShowTitle=FALSE, yShowTitle=FALSE,
                   xShowTickLabel=FALSE, yShowTickLabel=FALSE)
# Hide axis ticks
ggplot2.stripchart(data=df, xName='dose',yName='len',
                   xShowTitle=FALSE, yShowTitle=FALSE,
                   xShowTickLabel=FALSE, yShowTickLabel=FALSE,
                   hideAxisTicks=TRUE)
# AxisLine : a vector of length 3 indicating the size,
#the line type and the color of axis lines
ggplot2.stripchart(data=df, xName='dose',yName='len', 
                   axisLine=c(1, "solid", "darkblue"))
img_16178b98a20c6b779cb63f6d102bbdff.png

背景和颜色





# change background color to "white". Default is "gray"
ggplot2.stripchart(data=df, xName='dose',yName='len',
                   backgroundColor="white")
# Change background color to "lightblue" and grid color to "white"
ggplot2.stripchart(data=df, xName='dose',yName='len',
                   backgroundColor="lightblue", gridColor="white")
# Change plot fill color
ggplot2.stripchart(data=df, xName='dose',yName='len',
                   backgroundColor="white", fill='#FFAAD4')
# remove grid; remove top and right borders around the plot;
# change  axis lines
ggplot2.stripchart(data=df, xName='dose',yName='len',
                   backgroundColor="white", fill='#FFAAD4',
                   removePanelGrid=TRUE,removePanelBorder=TRUE,
                   axisLine=c(0.5, "solid", "black"))
img_6d04ecdcb5397c6588b2f7103f60f0e7.png
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值