R語言之可視化⑧easyGgplot2散點圖續目錄

目錄

R語言之可視化①誤差棒

R語言之可視化②點圖

R語言之可視化③點圖續

R語言之可視化④點韋恩圖upsetR

R語言之可視化⑤R圖形系統

R語言之可視化⑥R圖形系統續

R語言之可視化⑦easyGgplot2散點圖

R語言之可視化⑧easyGgplot2散點圖續

======================================

  • 根據組更改條形圖顏色

可以將顏色指定爲十六進制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'))
  • 標註/位置
# 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))
  • 標註背景邊框
# 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" )
    )
  • 隱藏標註
# 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)
  • 座標軸
# 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")
# 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")
# 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")
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章