目录
R语言之可视化①误差棒
R语言之可视化②点图
R语言之可视化③点图续
R语言之可视化④点韦恩图upsetR
R语言之可视化⑤R图形系统
R语言之可视化⑥R图形系统续
R语言之可视化⑦easyGgplot2散点图
======================================
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)
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")
更改条形图点的形状
# 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)
主要参数
更多信息:
主标题和坐标轴标签
# 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)
坐标轴
# 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"))
背景和颜色
# 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"))
网友评论