## 当pdf字体有问题时: ggsave('test.pdf', width=7,height=3, device = cairo_pdf, family = "Song")
Dot plot
geom_point
ggplot(mpg) +geom_point(mapping =aes( x =displ, y =hwy, color =class)) ggplot(mpg) +geom_point(mapping =aes( x =V1, y =V2, color =V3, shape =V4, size=V5))
+ geom_bar(stat= 'identity') ### the number of the point + geom_bar(aes(fill=group),stat="identity") ### the mean of all point (stack togather) + geom_bar(aes(fill=group),stat="summary",fun.y="mean",position = 'stack') ### dont stact + geom_bar(aes(fill=group),stat="summary",fun.y="mean",position = 'dodge')
## Best color for heatmap library(RColorBrewer) colorRampPalette(rev(brewer.pal(n = 7,name = "RdYlBu"))) -> cc simplot(d) + scale_fill_gradientn(colors=cc(100)) + theme()
legend.position = 'none'# delete legend legend.position = "left"# Position left legend.position = "right"# Position right legend.position = "bottom"# Position bottom legend.position = "top"# Position Top legend.position = c(0.9, 0.1) # relative postion in right-bottom.
Legends’ name
# alter in the given scale scale_color_gradient2(name = "My title")
# labs() labs(color = "title for color", size = "title for size", fill = "title for fill")
If the group number is larger than 3 and we still want to using the color from palette, one resolution is combine multiple color palettes. Another Resolution is using colors from a palette or a list again and again.
library("RColorBrewer")
G_number = 100 N = 12 P + scale_fill_manual(values= head(rep(brewer.pal(n = N, name = "Paired"),round(G_number/N)+1), G_number))
library("ggthemes")
## Gradient scale_fill_gradient() 允许分配一组双色连续渐变,low="white",high="red" scale_fill_gradient2() 允许分配一组三色连续渐变,low="blue",mid="white",high="red" ## sed a group of colour scale_fill_manual(values=c("Linen","Peru","PeachPuff","SandyBrown","Chocolate")) ## apply the Set on ggthemes + scale_colour_XXX() # Tab to see more + scale_color_gradient(low = "cyan",high = "red")
########################### ### Parameter of theme ########################### line #all line elements (element_line) rect #all rectangular elements (element_rect) text #all text elements (element_text) title #all title elements: plot, axes, legends (element_text; inherits from text) aspect.ratio #aspect ratio of the panel axis.title #label of axes (element_text; inherits from text) axis.title.x #x axis label (element_text; inherits from axis.title) axis.title.y #y axis label (element_text; inherits from axis.title) axis.tex #tick labels along axes (element_text; inherits from text) axis.text.x #x axis tick labels (element_text; inherits from axis.text) axis.text.y #y axis tick labels (element_text; inherits from axis.text) axis.ticks #tick marks along axes (element_line; inherits from line) axis.ticks.x #x axis tick marks (element_line; inherits from axis.ticks) axis.ticks.y #y axis tick marks (element_line; inherits from axis.ticks) axis.ticks.length #length of tick marks (unit) axis.line #lines along axes (element_line; inherits from line) axis.line.x #line along x axis (element_line; inherits from axis.line) axis.line.y #line along y axis (element_line; inherits from axis.line) legend.background #background of legend (element_rect; inherits from rect) legend.margin #extra space added around legend (unit) legend.key #background underneath legend keys (element_rect; inherits from rect) legend.key.size #size of legend keys (unit; inherits from legend.key.size) legend.key.height #key background height (unit; inherits from legend.key.size) legend.key.width #key background width (unit; inherits from legend.key.size) legend.text #legend item labels (element_text; inherits from text) legend.text.align #alignment of legend labels (number from 0 (left) to 1 (right)) legend.title #title of legend (element_text; inherits from title) legend.title.align #alignment of legend title (number from 0 (left) to 1 (right)) legend.position #the position of legends ("none", "left", "right", "bottom", "top", or two-element numeric vector) legend.direction #layout of items in legends ("horizontal" or "vertical") legend.justification #anchor point for positioning legend inside plot ("center" or two-element numeric vector) legend.box #arrangement of multiple legends ("horizontal" or "vertical") legend.box.just #justification of each legend within the overall bounding box, when there are multiple legends ("top", "bottom", "left", or "right") panel.background #background of plotting area, drawn underneath plot (element_rect; inherits from rect) panel.border #border around plotting area, drawn on top of plot so that it covers tick marks and grid lines. This should be used with fill=NA(element_rect; inherits from rect) panel.margin #margin around facet panels (unit) panel.margin.x #horizontal margin around facet panels (unit; inherits from panel.margin) panel.margin.y #vertical margin around facet panels (unit; inherits from panel.margin) panel.grid #grid lines (element_line; inherits from line) panel.grid.major #major grid lines (element_line; inherits from panel.grid) panel.grid.minor #minor grid lines (element_line; inherits from panel.grid) panel.grid.major.x #vertical major grid lines (element_line; inherits from panel.grid.major) panel.grid.major.y #horizontal major grid lines (element_line; inherits from panel.grid.major) panel.grid.minor.x #vertical minor grid lines (element_line; inherits from panel.grid.minor) panel.grid.minor.y #horizontal minor grid lines (element_line; inherits from panel.grid.minor) panel.ontop #option to place the panel (background, gridlines) over the data layers. Usually used with a transparent or blankpanel.background. (logical) plot.background #background of the entire plot (element_rect; inherits from rect) plot.title #plot title (text appearance) (element_text; inherits from title) plot.margin #margin around entire plot (unit with the sizes of the top, right, bottom, and left margins) strip.background #background of facet labels (element_rect; inherits from rect) strip.text #facet labels (element_text; inherits from text) strip.text.x #facet labels along horizontal direction (element_text; inherits from strip.text) strip.text.y #facet labels along vertical direction (element_text; inherits from strip.text) strip.switch.pad.grid #space between strips and axes when strips are switched (unit) strip.switch.pad.wrap #space between strips and axes when strips are switched (unit)