Plot in R, ggplot2

Plot in R, ggplot2

2016-10-11. Category & Tags: GGplot, GGplot2, R, 3D Plot

Python alternatives to ggplot2: pygg (NOT working), ggpy (ggplot in py) from yhat (NOT working and not in maintance). Please use rpy2 to “source()” R files.

Note: this blog is mainly used to prepare data, for plotting code, see:

3D PLOT #

scatter #

OBS: order of using commands.

surface #

OBS: order of using commands.

3rd dim as group for plot #

(paper 2 knn > 820_draft_plotAndTable_testCode.R)

# required data structure:  
#   k    variable      value  
#  32           8   6.885871  
#  64           8   7.345018  
# 128           8   8.005486  
# 256           8   8.964364  
#   2     1 (WPC)   5.557262  
# 256     1 (WPC)   5.557262  
#   2     2 (WPC)   5.560053  
# 256     2 (WPC)   5.560053  
#
# where, k is the x-axis, varialbe is the legend/group. the top half can come from the melt(dt, id = 'k') func with data below.  
#
#   k         1        2        4        8  // m, predict step  
#   2  7.302034 7.333397 7.396140 7.714781  
#   4  6.726445 6.738969 6.790104 7.091759  
#   8  6.449065 6.444127 6.534207 6.772768  
#  16  6.394377 6.392157 6.462557 6.677431  
#  32  6.620645 6.614758 6.682735 6.885871  
#  64  7.112442 7.109090 7.168172 7.345018

MULTI-PLOT #

old base plot commands #

// ignored.

ggplot with a user-defined function #

Using just one user-defined function, easy to do.
Solution from R cookbook online. backup.

More examples of multiplot() from here. backup.

Problem: ggsave() cannot know this combined plot, need to use picture devices to save, e.g. png(...); dev.off();.

cowplot #

have not tried.
see here. backup.