ggplot2 easyplot②

  • 根据组更改条形图颜色

可以将颜色指定为十六进制RGB三元组,例如“#FFCC00”或名称。还可以使用其他颜色比例,例如从RColorBrewer包中提取的颜色比例。 这里已经详细描述了R中可用的不同颜色系统。
要根据组更改条形图颜色,必须使用参数groupName指定包含组的数据列的名称。 使用参数groupColors,通过十六进制代码或名称指定颜色。 在这种情况下,groupColors的长度应该与组的数量相同。 使用参brewerPalette,使用RColorBrewerpalette指定颜色。

# Color the stripchart accoording to the groupName "dose"
ggplot2.stripchart(data=df, xName='dose',yName='len',
        groupName='dose')
# Change group colors using hexadecimal colors
ggplot2.stripchart(data=df, xName='dose',yName='len',
        groupName='dose',
        groupColors=c('#999999','#E69F00','#56B4E9'))
# Change group colors using brewer palette: "Paired"
ggplot2.stripchart(data=df, xName='dose',yName='len',
        groupName='dose',brewerPalette="Paired")
# Change group colors using color names
ggplot2.stripchart(data=df, xName='dose',yName='len',
      groupName='dose',
      groupColors=c('aquamarine3','chartreuse1','goldenrod1'))
img_aa06d5493c4cf33ac23589ed262b9c2d.png
  • 标注/位置
# Change the legend position to "top" 
  # (possible values: "left","top", "right", "bottom")
ggplot2.stripchart(data=df, xName='dose',yName='len',
        groupName='dose', legendPosition="top")
# legendPosition can be also a numeric vector c(x, y)
ggplot2.stripchart(data=df, xName='dose',yName='len',
        groupName='dose', legendPosition=c(0.8,0.2))
img_09ecac4681fe89b395c479b409cc58f5.png
  • 标注背景边框
# Change legend background color, title and text font styles
ggplot2.stripchart(data=df, xName='dose',yName='len',
    groupName='dose',
    #legendTitleFont=c(size, style, color)
    legendTitle="Dose (mg)", legendTitleFont=c(10, "bold", "blue"),
    #legendTextFont=c(size, style, color)
    legendTextFont=c(10, "bold.italic", "red"),
    #legendBackground: c(fill, lineSize, lineType, lineColor)
    legendBackground=c("lightblue", 0.5, "solid", "darkblue" )
    )
img_fc54fe6ff44d826a830e0359bf6fcf9d.png
  • 隐藏标注
# Change the order of items in the legend
 # legendItemOrder : character vector indicating 
# the order of items in the legends.
ggplot2.stripchart(data=df, xName='dose',yName='len',
            groupName='dose',
            legendItemOrder=c("2", "1", "0.5"))
# Remove plot legend
ggplot2.stripchart(data=df, xName='dose',yName='len',
              groupName='dose', showLegend=FALSE)
img_c03ae486e86b6b57253b782f60df4f99.png
  • 坐标轴
# Change y axis limit
ggplot2.stripchart(data=df, xName='dose',yName='len',
                groupName='dose', ylim=c(0,50))
# y Log scale. yScale="log2". 
# Possible value="none", "log2" and "log10"
ggplot2.stripchart(data=df, xName='dose',yName='len',
              groupName='dose', yScale="log2")
img_2a676adbe7563785fb04f952e9ef0917.png
# Customized stripchart
ggplot2.stripchart(data=df, xName='dose',yName='len',
    groupName='dose',
    groupColors=c('#999999','#E69F00','#56B4E9'), showLegend=FALSE,
    backgroundColor="white", xtitle="Dose (mg)", ytitle="length", 
    mainTitle="Plot of length \n by dose")
# Customized stripchart with notched box plot
# Remove grid; Remove Top and right border around the plot
ggplot2.stripchart(data=df, xName='dose',yName='len',
    groupName='dose',
    groupColors=c('#999999','#E69F00','#56B4E9'), showLegend=FALSE,
    backgroundColor="white", xtitle="Dose (mg)", ytitle="length", 
    mainTitle="Plot of length \n by dose",
    addBoxplot=TRUE, notch=TRUE,
    removePanelGrid=TRUE,removePanelBorder=TRUE,
    axisLine=c(0.5, "solid", "black"))
# Customized stripchart, change point color, 
# fill box plot accoording to the groups
#Change the color of points to "black"
ggplot2.stripchart(data=df, xName='dose',yName='len',
    groupName='dose',
    groupColors=c('#999999','#E69F00','#56B4E9'), showLegend=FALSE,
    backgroundColor="white", xtitle="Dose (mg)", ytitle="length", 
    mainTitle="Plot of length \n by dose",
    addBoxplot=TRUE, boxplotFill=NULL, notch=TRUE, colour="black")
img_c6a86677c36f4a64d82c23bfd928eb2b.png
# Customized stripchart, add box plot, pink fill color.
# Change the color of points to "black"
ggplot2.stripchart(data=df, xName='dose',yName='len',
    groupName='dose',
    groupColors=c('#999999','#E69F00','#56B4E9'), showLegend=FALSE,
    backgroundColor="white", xtitle="Dose (mg)", ytitle="length", 
    mainTitle="Plot of length \n by dose",
    addBoxplot=TRUE, boxplotFill="pink", colour="black")
# Customized stripchart, add box plot, 
#fill box plot accoording to the groups.
ggplot2.stripchart(data=df, xName='dose',yName='len',
    groupName='dose',
    groupColors=c('#999999','#E69F00','#56B4E9'),
    showLegend=FALSE,
    backgroundColor="white", xtitle="Dose (mg)", ytitle="length", 
    mainTitle="Plot of length \n by dose",
    addBoxplot=TRUE, boxplotFill=NULL, colour="black")
# plot of variable 'len' by xName 'dose'. The plot is colored by the groupName 'supp'
# position = interval between dot plot of the same group
ggplot2.stripchart(data=df, xName='dose',yName='len',
      groupName='supp', 
      position=position_jitter(0.2), 
      backgroundColor="white", 
      groupColors=c('#999999','#E69F00')
)  
 
# Change the interval between stripchart of the same group:
  # position = interval between dot plot of the same group
ggplot2.stripchart(data=df, xName='dose',yName='len',
      groupName='supp', 
      position=position_dodge(0.8), 
      backgroundColor="white", groupColors=c('#999999','#E69F00'))
# Change the interval between stripchart of the same group
#position=position_dodge(0.8), add box plot
ggplot2.stripchart(data=df, xName='dose',yName='len',
      groupName='supp', 
      position=position_dodge(0.8), 
      backgroundColor="white", groupColors=c('#999999','#E69F00'),
      addBoxplot=TRUE, boxplotFill="white")
img_863e9c1eaf1169aeb5bb496effad8a89.png
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值