gravatar

Gren

Renee

Recently Published

plotggPlot
gg = ggplot(diamonds, aes(x, depth)) + stat_density_2d(aes(fill = stat(nlevel)), geom = "polygon", n = 100,bins = 10, contour = TRUE) + facet_wrap(clarity~.) + scale_fill_viridis_c(option = "A") plot_gg(gg,multicore=TRUE,width=5, height=5,scale=250)
surf3DPlot
par(mar = c(2, 2, 2, 2)) par(mfrow = c(1, 1)) R <- 3 r <- 2 x <- seq(0, 2*pi,length.out=50) y <- seq(0, pi,length.out=50) M <- mesh(x, y) alpha <- M$x beta <- M$y surf3D(x = (R + r*cos(alpha)) * cos(beta), y = (R + r*cos(alpha)) * sin(beta), z = r * sin(alpha), colkey=FALSE, bty="b2", main="Half of a Torus")
image3DPlot
Vx <- volcano[-1, ] - volcano[-nrow(volcano), ] image3D(z = -60, colvar = Vx/10, add = TRUE, colkey = list(length = 0.2, width = 0.4, shift = -0.15, cex.axis = 0.8, cex.clab = 0.85), clab = c("","gradient","m/m"), plot = FALSE) contour3D(z = -60+0.01, colvar = Vx/10, add = TRUE, col = "black", plot = TRUE)
image2DPlot
image2D(z = Oxsat$val, subset = sub, x = Oxsat$lon, y = Oxsat$lat, margin = c(1, 2), NAcol = "cyan", colkey = FALSE, xlab = "longitude", ylab = "latitude", main = paste("depth ", Oxsat$depth[sub], " m"), clim = c(0, 115), mfrow = c(2, 2)) colkey(clim = c(0, 115), clab = c("O2 saturation", "percent"))
arrow3DPlot
arrows2D(x0 = runif(10), y0 = runif(10), x1 = runif(10), y1 = runif(10), colvar = 1:10, code = 3, main = "arrows2D") arrows3D(x0 = runif(10), y0 = runif(10), z0 = runif(10), x1 = runif(10), y1 = runif(10), z1 = runif(10), colvar = 1:10, code = 1:3, main = "arrows3D", colkey = FALSE)
scatter3DPlot
zmin <- min(-quakes$depth) XY <- trans3D(quakes$long, quakes$lat, z = rep(zmin, nrow(quakes)), pmat = pmat) scatter2D(XY$x, XY$y, colvar = quakes$mag, pch = ".", cex = 2, add = TRUE, colkey = FALSE) xmin <- min(quakes$long) XY <- trans3D(x = rep(xmin, nrow(quakes)), y = quakes$lat, z = -quakes$depth, pmat = pmat) scatter2D(XY$x, XY$y, colvar = quakes$mag, pch = ".", cex = 2, add = TRUE, colkey = FALSE)
surf3DPlot
M <- mesh(seq(-13.2, 13.2, length.out = 50), seq(-37.4, 37.4, length.out = 50)) u <- M$x ; v <- M$yb <- 0.4; r <- 1 - b^2; w <- sqrt(r) D <- b*((w*cosh(b*u))^2 + (b*sin(w*v))^2) x <- -u + (2*r*cosh(b*u)*sinh(b*u)) / D y <- (2*w*cosh(b*u)*(-(w*cos(v)*cos(w*v)) - sin(v)*sin(w*v))) / D z <- (2*w*cosh(b*u)*(-(w*sin(v)*cos(w*v)) + cos(v)*sin(w*v))) / D surf3D(x, y, z, colvar = sqrt(x + 8.3), colkey = FALSE, border = "black", box = FALSE)
persp3DPlot
persp3D(z = Hypsometry$z[ii,jj], xlab = "longitude", bty = "bl2", ylab = "latitude", zlab = "depth", clab = "depth, m", expand = 0.5, d = 2, phi = 20, theta = 30, resfac = 2, contour = list(col = "grey", side = c("zmin", "z")), zlim = zlim, colkey = list(side = 1, length = 0.5))
rgl3DPlot
image3D(z = -60, colvar = Vx/10, add = TRUE, colkey = list(length = 0.2, width = 0.4, shift = -0.15, cex.axis = 0.8, cex.clab = 0.85), clab = c("","gradient","m/m"), plot = FALSE) contour3D(z = -60+0.01, colvar = Vx/10, add = TRUE, col = "black", plot = TRUE)
pie3DPlot
#png(file = "3d_pie_chart.jpg") # Plot the chart. pie3D(x,labels = lbl,explode = 0.1, main = "Pie Chart of Countries ") # Save the file. dev.off()
plotlyHTML
ggplot(df, aes(carat, price)) + geom_point(color="plum",alpha=0.3) + ggtitle("Diamonds") + xlab("x-axis -> Carat") + ylab("y-axis -> Price")
sdNormDHTML
norm1 <- data.frame(x=x, y=dnorm(x,mean = 0, sd=1)) norm2 <- data.frame(x=x, y=dnorm(x,mean = 0, sd=1.2)) norm3 <- data.frame(x=x, y=dnorm(x,mean = 0, sd=1.5)) norm4 <- data.frame(x=x, y=dnorm(x,mean = 0, sd=2))
CirclePlot
ggplot(data = ad, aes(fill = type, ymax = ymax, ymin = ymin, xmax = 4, xmin = 3)) + geom_rect(show.legend = F,alpha=0.9) + scale_fill_brewer(palette = 'Set3')+ coord_polar(theta = "y") + labs(x = "", y = "", title = "",fill='Rigion') + xlim(c(0, 5)) + geom_text(aes(x = 2, y = ((ymin+ymax)/2), label = type) ,size=2)
chordDPlot
mat <- matrix(rnorm(36), 6, 6) rownames(mat) <- paste0("R", 1:6) colnames(mat) <- paste0("C", 1:6) mat[2, ] <- 1e-10 mat[, 3] <- 1e-10 chordDiagram(mat)
annotationTrackPlot
par(mfrow = c(1, 3)) chordDiagram(mat, grid.col = grid_col, annotationTrack = "grid") chordDiagram(mat, grid.col = grid_col, annotationTrack = c("name", "grid"), annotationTrackHeight = c(0.03, 0.01)) chordDiagram(mat, grid.col = grid_col, annotationTrack = NULL)
arrowChordDPlot
arr_col <- data.frame(c("S1", "S2", "S3"), c("E5", "E6", "E4"), c("black", "black", "black")) chordDiagram(mat, grid.col = grid_col, directional = 1, link.arr.col = arr_col, direction.type = "arrows", link.arr.length = 0.2) chordDiagram(mat, grid.col = grid_col, directional = 1, direction.type = c("diffHeight", "arrows"), link.arr.col = arr_col, link.arr.length = 0.2)
gridChordDPlot
mat2 <- matrix(sample(100, 35), nrow = 5) rownames(mat2) <- letters[1:5] colnames(mat2) <- letters[1:7] mat2 chordDiagram(mat2, grid.col = 1:7, directional = 1, row.col = 1:2)
chordDGridPlot
par(mfrow = c(1, 3)) chordDiagram(mat, grid.col = grid_col, directional = 1) chordDiagram(mat, grid.col = grid_col, directional = 1, diffHeight = uh(5, "mm")) chordDiagram(mat, grid.col = grid_col, directional = -1)
symmetricChrodDPlot
col_fun <- colorRamp2(c(-1, 0, 1), c("green", "white", "red")) chordDiagram(cor_mat, grid.col = 1:5, symmetric = TRUE, col = col_fun) title("symmetric = TRUE") chordDiagram(cor_mat, grid.col = 1:5, col = col_fun)
chordDiagramPlot
chordDiagram(mat, grid.col = grid_col, link.border = "red") lwd_mat <- matrix(1, nrow = nrow(mat), ncol = ncol(mat)) lwd_mat[mat > 12] <- 2 border_mat <- matrix(NA, nrow = nrow(mat), ncol = ncol(mat)) border_mat[mat > 12] <- "red"
CirclizePlot
Convert to polar coordinate system Usage circlize( x, y, sector.index = get.current.sector.index(), track.index = get.current.track.index())
clustCombiPlot
data(Baudry_etal_2010_JCGS_examples) output <- clustCombi(data = ex4.4.1) output # is of class clustCombi # plots the hierarchy of combined solutions, then some "entropy plots" # may help one to select the number of classes plot(output)
ggscatmatPlot
This function makes a scatterplot matrix for quantitative variables with density plots on the diagonal and correlation printed in the upper triangle. ggscatmat( data, columns = 1:ncol(data), color = NULL, alpha = 1, corMethod = "pearson" )
scatterPlotMatrixPlot
interface to the pairs function to produce enhanced scatterplot matrices, including univariate displays on the diagonal and a variety of fitted lines, smoothers, variance functions, and concentration ellipsoids. spm is an abbreviation for scatterplotMatrix(~ income + education + prestige | type, data=Duncan)
coMapPlot
lat ~ long | depth, data = quakes, number = 4, ylim = c(-45, -10.72), panel = function(x, y, ...) { map("world2", regions = c("New Zealand","Fiji"), add = TRUE, lwd = 0.1, fill = TRUE,col = "lightgray") text(180, -13, "Fiji", adj = 1) text(170, -35, "NZ") points(x, y, col = rgb(0.2, 0.2, 0.2, 0.5)) }
ggpairGgallyPlot
ggpairs( diamonds.samp[, c(1:2,5,7)], mapping = aes(color = cut), lower = list(continuous = wrap("density", alpha = 0.5), combo = "dot_no_facet"), title = "Diamonds" )
panelCorPlot
pairs(iris[1:4], main = "Anderson's Iris Data -- 3 species", pch = 21, bg = c("red", "cyan", "blue")[unclass(iris$Species)], diag.panel=panel.hist, upper.panel=panel.cor, lower.panel=panel.lm)
pairsCorPlot
pairs(~Sepal.Length+Sepal.Width+ Petal.Length+Petal.Width, data=iris,main = "Anderson's IrisData3 species", pch = 21, bg = c("red", "cyan", "blue") [unclass(iris$Species)])
cpairsPlot
gclust: The Genie++ Hierarchical Clustering Algorithm #cpairs{gclus} library(gclus) data(USJudgeRatings) judge.cor <- cor(USJudgeRatings) judge.color <- dmat.color(judge.cor) cpairs(USJudgeRatings, panel.colors=judge.color, pch=".",gap=.5)
ggraphCirclePlot
ggraph(mygraph, layout = 'dendrogram',circular = TRUE+geom_edge_diagonal(aes(colour=..index..)+scale_edge_colour_distiller(palette = "RdPu"+geom_node_text(aes(x=x*1.25, y=y*1.25, angle=angle, label=name, color=group), size=2.7, alpha=1+ geom_node_point(aes(x = x*1.07, y=y*1.07, fill=group, size=value), shape=21, stroke=0.2, color='black', alpha=1)
CircleFunctionPlot
for(i in 1:nr){circos.rect(1:nc -1, rep(nr - i, nc), 1:nc, rep(nr - i + 1, nc), border = 'black', col = col_data[i, ], size=0.1)} circos.text(CELL_META$xcenter, CELL_META$cell.ylim[1]+uy(25, "mm"), CELL_META$sector.index) circos.axis(labels.cex = 1, major.at = seq(0.5, round(CELL_META$xlim[2])+0.5,2), labels=seq(0, round(CELL_META$xlim[2]),2)) })
viridisigraphPlot
mygraph <- graph_from_data_frame(edges, vertices=vertices) ggraph(mygraph, layout = 'circlepack', weight= 2 )+geom_node_circle(aes(fill = depth))+geom_node_text(aes(label=shortName, filter=leaf, fill=depth, size=5))+ theme_void()+theme(legend.position="FALSE")+ scale_fill_viridis()
meltReshapePlot
ggplot(data=mydata,aes(x=id, y=value,group=variable,fill=variable)) + geom_polygon(colour="black",alpha=0.1)+ geom_point(size=4,shape=21,color = 'black')+ #coord_radar()+coord_polar() +scale_x_continuous(breaks=label_data$id, labels=label_data$car)+ theme_bw() +ylim(0,22)+theme
coordPloarPlot
ggplot(mydata, aes(x = id, y = value)) + geom_polygon(color = "black", fill = brewer.pal(7, "Set1")[3], alpha = 0.1) + geom_point(size = 5, shape = 21, color = "black", fill = brewer.pal(7, "Set1")[1]) +coord_polar()
singlePolarPlot
theme( panel.background = element_blank(), panel.grid.major = element_line(colour = "grey80", size=.25), axis.text.y = element_text(size = 12, colour = "black"), axis.line.y = element_line(size = 0.25), axis.text.x = element_text(size = 13, colour = "black", angle = myAngle))
coordpolarPlot
ggplot(data=df, aes(item, value, fill=score)) +geom_bar(stat="identity", color="plum", position = position_dodge(),width = 0.7, size=0.25)+coord_polar(theta = "x", start=0)+ylim(c(-3,6)) + scale_fill_brewer(palette = "Reds") + theme_light()+theme(axis.title = element_text(size =13,color = "plum", angle = myAng))
nantingaleRoseChartPlot
myAngle <- seq(-20, -340, length.out = 8) ggplot(diamonds, aes(x=clarity, fill=color)) + geom_bar(width = 1.0, colour = "black", size = 0.25) + coord_polar(theta = "x", start = 0) + # scale_fill_brewer(palette = "Reds") + guides(fill = guide_legend(reverse = TRUE, title = "Color")) + ylim(c(-2000,12000)) +theme_light() + theme(axis.text.x = element_text(size = 13, colour = "black", angle = myAngle) )
heatMapPlot
set.seed(1) data <- data.frame(x = rnorm(100), y = rnorm(100)) data$z <- with(data, x * y + rnorm(100, sd = 1)) # showing data points on the same color scale levelplot(z ~ x * y, data, panel = panel.levelplot.points, cex = 1.2 ) + layer_(panel.2dsmoother(..., n = 200))
calendarHeatmapPlot
# Create Month Week df$yearmonth <- as.yearmon(df$date) df$yearmonthf <- factor(df$yearmonth) df <- ddply(df,.(yearmonthf), transform, monthweek=1+week-min(week)) df <- df[, c("year", "yearmonthf", "monthf", "week", "monthweek", "weekdayf", "VIX.Close")]
clusterinencirclegPlot
coord_cartesian(xlim = 1.2 * c(min(df_pc$PC1), max(df_pc$PC1)), ylim = 1.2 * c(min(df_pc$PC2), max(df_pc$PC2))) + geom_encircle(data = df_pc_vir, aes(x=PC1, y=PC2)) + geom_encircle(data = df_pc_set, aes(x=PC1, y=PC2)) + geom_encircle(data = df_pc_ver, aes(x=PC1, y=PC2))
stackedAreaPlot
labs(title="Area Chart of Returns Percentage", subtitle="From Wide Data format", caption="Source: Economics", y="Returns %") + scale_x_date(labels = lbls, breaks = brks) + scale_fill_manual(name="", values = c("psavert"="#00ba38", "uempmed"="#f8766d")) + theme(panel.grid.minor = element_blank())
timeSeriesPlot
df <- economics_long[economics_long$variable %in% c("psavert", "uempmed"), ] df <- df[lubridate::year(df$date) %in% c(1967:1981), ] # labels and breaks for X axis text brks <- df$date[seq(1, length(df$date), 12)] lbls <- lubridate::year(brks)
ggmarginalhistsogramPlot
# Set relative size of marginal plots (main plot 10x bigger than marginals) ggMarginal(p, type="histogram", size=10) # Custom marginal plots: ggMarginal(p, type="histogram", fill = "slateblue", xparams = list( bins=10))
ggMarginalBoxPlot
# Set relative size of marginal plots (main plot 10x bigger than marginals) ggMarginal(p, type="histogram", size=10) # Custom marginal plots: ggMarginal(p, type="histogram", fill = "slateblue", xparams = list( bins=10)) # Show only marginal plot for x axis ggMarginal(p, margins = 'x', color="purple", size=4)
ggMarginalDensPlot
# Show only marginal plot for x axis ggMarginal(p, margins = 'x', color="purple", size=4)
ggMarginalhistPlot
ggMarginal(g, type = "histogram", fill="transparent") ggMarginal(g, type = "boxplot", fill="transparent") # ggMarginal(g, type = "density", fill="transparent")
ggMarginalPlot
gMarginal(g, type = "histogram", fill="transparent") ggMarginal(g, type = "boxplot", fill="transparent") # ggMarginal(g, type = "density", fill="transparent")
geomgPlot
# plot ggplot(data=iris, aes(x=Sepal.Length, Petal.Length)) + geom_point() + geom_rug(col="steelblue",alpha=0.1, size=1.5)
multidimPlot
r = moxbuller(50000) par(bg="white") par(mar=c(0,0,0,0)) plot(r$x,r$y, pch=".", col="blue", cex=1.2)
prettyBubblePlot
data %>%arrange(desc(pop)) %>%mutate(country = factor(country, country)) %>%ggplot(aes(x=gdpPercap, y=lifeExp, size=pop, fill=continent)) +scale_fill_viridis(discrete=TRUE, guide=FALSE, option="A")
scaleSizePlot
data %>% arrange(desc(pop)) %>% mutate(country = factor(country, country)) %>% ggplot(aes(x=gdpPercap, y=lifeExp, size=pop, color=continent)) + geom_point(alpha=0.5) + scale_size(range = c(.1, 24), name="Population (M)")
ggplotjitterPlot
ggplot( aes(x=name, y=value, fill=name)) +geom_boxplot() + scale_fill_viridis(discrete = TRUE, alpha=0.6) +geom_jitter(color="black", size=0.4, alpha=0.9) +theme_ipsum() +theme( legend.position="none", plot.title = element_text(size=11) ) +ggtitle("A boxplot with jitter") + xlab("")
ggplotGridArrangePlot
g3 <- ggplot(mtcars, aes(x=factor(cyl), y=qsec, fill=cyl)) + geom_boxplot() + theme(legend.position="none") g4 <- ggplot(mtcars , aes(x=factor(cyl), fill=factor(cyl))) + geom_bar() grid.arrange(g2, arrangeGrob(g3, g4, ncol=2), nrow = 2) grid.arrange(g1, g2, g3, nrow = 3)
scatterCylinderPlot
scatterplotMatrix(~mpg+disp+drat|cyl, data=data , reg.line="" , smoother="", col=my_colors , smoother.args=list(col="grey") , cex=1.5 , pch=c(15,16,17) , main=" ")
corrMtcarsPlot
#Correlation matrix with ggally # Data: numeric variables of the native mtcars dataset data <- mtcars[ , c(1,3:6)] # Plot plot(data , pch=20 , cex=1.5 , col="#69b3a2")
corrgramPlot
corrgram(mtcars, order=TRUE, lower.panel=panel.shade, upper.panel=panel.pie, text.panel=panel.txt, main="Car Milage Data in PC2/PC1 Order")
corrEllipsePlot
library(ellipse) library(RColorBrewer) # Use of the mtcars data proposed by R data <- cor(mtcars) my_colors <- brewer.pal(5, "Spectral") my_colors <- colorRampPalette(my_colors)(100) ord <- order(data[1, ]) data_ord <- data[ord, ord] plotcorr(data_ord , col=my_colors[data_ord*50+50] , mar=c(1,1,1,1) )
correlationVariablesPlot
# Quick display of two cabapilities of GGally, to assess the distribution and correlation of variables library(GGally) # From the help page: data(tips, package = "reshape") ggpairs( tips[, c(1, 3, 4, 2)], upper = list(continuous = "density", combo = "box_no_facet"), lower = list(continuous = "points", combo = "dot_no_facet") )
correlationMatrixggallyPlot
# Quick display of two cabapilities of GGally, to assess the distribution and correlation of variables library(GGally) # From the help page: data(flea) ggpairs(flea, columns = 2:4, ggplot2::aes(colour=species))
correlationMatrixPlot
data <- data.frame( var1 = 1:100 + rnorm(100,sd=20), v2 = 1:100 + rnorm(100,sd=27), v3 = rep(1, 100) + rnorm(100, sd = 1)) data$v4 = data$var1 ** 2 data$v5 = -(data$var1 ** 2) ggpairs(data, title="correlogramGgpairs()")
hexbinPlot
bin<-hexbin(x, y, xbins=40) my_colors=colorRampPalette (rev(brewer.pal(11,'Spectral'))) plot(bin, main="" , colramp=my_colors , legend=F )
tanglegramPlot
# Plot them together tanglegram(dl, common_subtrees_color_lines = FALSE, highlight_distinct_edges = TRUE, highlight_branches_lwd=FALSE, margin_inner=7, lwd=2 )
dendextendPlot
# Color in function of the cluster par(mar=c(1,1,1,7)) dend %>% set("labels_col", value = c("skyblue", "orange", "grey"), k=3) %>% set("branches_k_color", value = c("skyblue", "orange", "grey"), k = 3) %>% plot(horiz=TRUE, axes=FALSE) abline(v = 350, lty = 2)
dendrogramPlot
dend %>% set("labels_col", value = c("skyblue", "orange", "grey"), k=3) %>% set("branches_k_color", value = c("skyblue", "orange", "grey"), k = 3) %>% plot(axes=FALSE) rect.dendrogram( dend, k=3, lty = 5, lwd = 0, x=1, col=rgb(0.1, 0.2, 0.4, 0.1) )
gapmindHTML
library(ggplot2) library(plotly) library(gapminder) p <- gapminder %>% filter(year==1977) %>% ggplot( aes(gdpPercap, lifeExp, size = pop, color=continent)) + geom_point() + theme_bw() ggplotly(p)
ggridges2Plot
ggplot(lincoln_weather, aes(x = `Mean Temperature [F]`, y = `Month`, fill = ..x..)) +geom_density_ridges_gradient (scale = 3, rel_min_height = 0.01) +scale_fill_viridis (name = "Temp. [F]", option = "C") + labs(title = 'Temperatures in Lincoln NE in 2016') + theme_ipsum() +theme(legend.position="none", panel.spacing = unit(0.1, "lines"),strip.text.x = element_text(size = 8))
ggridges1Plot
# Plot data %>% mutate(text = fct_reorder(text, value)) %>% ggplot( aes(y=text, x=value, fill=text)) + geom_density_ridges(alpha=0.6, stat="binline", bins=20) + theme_ridges() + theme( legend.position="none", panel.spacing = unit(0.1, "lines"), strip.text.x = element_text(size = 8) ) + xlab("") + ylab("Assigned Probability (%)")
ggridgesPlot
# library library(ggridges) library(ggplot2) # Diamonds dataset is provided by R natively #head(diamonds) # basic example ggplot(diamonds, aes(x = price, y = cut, fill = cut)) + geom_density_ridges() + theme_ridges() + theme(legend.position = "none")
wordCloudStarHTML
wordcloud2(demoFreq, size = 0.7, shape = 'star') # Change the shape using your image wordcloud2(demoFreq, figPath = "gallery/img/other/peaceAndLove.jpg", size = 1.5, color = "skyblue", backgroundColor="black")
wordCloud21HTML
wordcloud2(demoFreq, size=1.6, color=rep_len( c("green","blue"), nrow(demoFreq) ) )wordcloud2(demoFreq, size=1.6, color='random-light')
wordCloud2HTML
# library library(wordcloud2) # wordcloud wordcloud2(demoFreq, size = 2.3, minRotation = -pi/6, maxRotation = -pi/6, rotateRatio = 1)
worldCloudHTML
worldCloud2 # wordcloud wordcloud2(demoFreqC, size = 2, fontFamily = "FranklinGothic Medium", color = "random-light", backgroundColor = "grey")
radarColorPlot
radarchart( data[-c(1,2),] , axistype=0 , maxmin=F, #custom polygon pcol=colors_border , pfcol=colors_in , plwd=4 , plty=1, #custom the grid cglcol="grey", cglty=1, axislabcol="black", cglwd=0.8, #custom labels vlcex=0.8 )
radarchartPlot
radarchart( data , axistype=1 , #custom polygon pcol=colors_border , pfcol=colors_in , plwd=4 , plty=1, #custom the grid cglcol="grey", cglty=1, axislabcol="grey", caxislabels=seq(0,20,5), cglwd=0.8, #custom labels vlcex=0.8 )
radarPlot
# Library library(fmsb) # Create data: note in High school for several students set.seed(99) data <- as.data.frame(matrix( sample( 0:20 , 15 , replace=F) , ncol=5)) colnames(data) <- c("math" , "english" , "biology" , "music" , "R-coding" ) rownames(data) <- paste("mister" , letters[1:3] , sep="-") # To use the fmsb package, I have to add 2 lines to the data <- rbind(rep(20,5) , rep(0,5) , data) # plot with default options: radarchart(data)
addBaseLinePlot
# prepare a data frame for grid (scales) grid_data <- base_data grid_data$end <- grid_data$end[ c( nrow(grid_data), 1:nrow(grid_data)-1)] + 1 grid_data$start <- grid_data$start - 1 grid_data <- grid_data[-1,] # Make the plot p <- ggplot(data, aes(x=as.factor(id), y=value, fill=group)) + geom_segment(data=grid_data, aes(x = end, y = 80, xend = start, yend = 80), colour = "grey", alpha=1, size=0.3 , inherit.aes = FALSE ) +
circularBarplotPlot
ggplot(data, aes(x=as.factor(id), y=value, fill=group)) + geom_bar(stat="identity", alpha=0.5) + ylim(-100,120) + theme_minimal() +theme( axis.text = element_blank(), axis.title = element_blank(), panel.grid = element_blank(), plot.margin = unit(rep(-1,4), "cm") ) +coord_polar() + geom_text(data=label_data, aes(x=id, y=value+10, label=individual, hjust=hjust), color="black", fontface="bold",alpha=0.6, size=2.5, angle= label_data$angle, inherit.aes = FALSE )
circleBarPlotPlot
p <- ggplot(data, aes(x=as.factor(id), y=value)) + geom_bar(stat="identity", fill=alpha("cyan", 0.7)) + ylim(-100,120) + theme_minimal() + theme( axis.text = element_blank(), axis.title = element_blank(), panel.grid = element_blank(), plot.margin = unit(rep(-1,4), "cm") ) + coord_polar(start = 0) + geom_text(data=label_data, aes(x=id, y=value+10, label=individual, hjust=hjust), color="black", fontface="bold",alpha=0.6, size=2.5, angle= label_data$angle, inherit.aes = FALSE )
ggraphPlot
ggraph(mygraph, layout = 'dendrogram', circular = TRUE) + geom_node_point(aes(filter = leaf, x = x*1.05, y=y*1.05)) + geom_conn_bundle(data = get_con(from = from, to = to), alpha=0.2, colour="skyblue", width=0.9) + geom_node_text(aes(x = x*1.1, y=y*1.1, filter = leaf, label=name, angle = angle, hjust=hjust), size=1.5, alpha=1) + theme_void() + theme( legend.position="none", plot.margin=unit(c(0,0,0,0),"cm"), ) + expand_limits(x = c(-1.2, 1.2), y = c(-1.2, 1.2))
cartographyPlot
choroLayer(spdf = nuts2.spdf, df = nuts2.df, var = "cagr", breaks = c(-2.43, -1, 0, 0.5, 1, 2, 3.1), col = cols, border = "grey40", lwd = 0.5, legend.pos = "right", legend.title.txt = "taux de croissance\nannuel moyen", legend.values.rnd = 2, add = TRUE) # Add borders plot(nuts0.spdf, border = "grey20", lwd = 0.75, add = TRUE) # Add titles, legend ... layoutLayer(title = "Growth rate in Europe", author = "cartography", sources = "Eurostat, 2008", frame = TRUE, col = NA, scale = NULL, coltitle = "black", south = TRUE)
InteractivePlotHTML
p <- data %>% ggplot() + geom_polygon(data = UK, aes(x=long, y = lat, group = group), fill="grey", alpha=0.3) + geom_point(aes(x=long, y=lat, size=pop, color=pop, text=mytext, alpha=pop) ) + scale_size_continuous(range=c(1,15)) + scale_color_viridis(option="inferno", trans="log" ) + scale_alpha_continuous(trans="log") + theme_void() + ylim(50,59) + coord_map() + theme(legend.position = "none") p <- ggplotly(p, tooltip="text")
geomPlot
data %>% arrange(desc(pop)) %>% mutate( name=factor(name, unique(name))) %>% ggplot() + geom_polygon(data = UK, aes(x=long, y = lat, group = group), fill="grey", alpha=0.3) + geom_point( aes(x=long, y=lat, size=pop, color=pop), alpha=0.9) + scale_size_continuous(range=c(1,12)) + scale_color_viridis(trans="log") + theme_void() + ylim(50,59) + coord_map() + theme(legend.position="none")
polygonPlot
ggplot() + geom_polygon(data = UK, aes(x=long, y = lat, group = group), fill="grey", alpha=0.3) + geom_point( data=data, aes(x=long, y=lat, size=pop, color=pop)) + scale_size_continuous(range=c(1,12)) + scale_color_viridis(trans="log") + theme_void() + ylim(50,59) + coord_map()
mapprojPlot
library(ggrepel) ggplot() + geom_polygon(data = UK, aes(x=long, y = lat, group = group), fill="grey", alpha=0.3) +geom_point( data=data, aes(x=long, y=lat, alpha=pop)) + geom_text_repel( data=data %>% arrange(pop) %>% tail(10), aes(x=long, y=lat, label=name), size=5) + geom_point( data=data %>% arrange(pop) %>% tail(10), aes(x=long, y=lat), color="red", size=3) +theme_void() + ylim(50,59) + coord_map() +theme(legend.position="none")
worldConnectionPlot
# map 3 connections: great <- getGreatCircle(Paris, Melbourne) lines(great, col="skyblue", lwd=2) great <- getGreatCircle(Buenos_aires, Melbourne) lines(great, col="skyblue", lwd=2) great <- getGreatCircle(Paris, Buenos_aires) lines(great, col="skyblue", lwd=2) points(x=data$long, y=data$lat, col="slateblue", cex=3, pch=20) text(rownames(data), x=data$long, y=data$lat, col="slateblue", cex=1, pos=4)
addeveryconnectionPlot
# add every connections: for(i in 1:nrow(all_pairs)){ plot_my_connection(all_pairs$long1[i], all_pairs$lat1[i], all_pairs$long2[i], all_pairs$lat2[i], col="skyblue", lwd=1) } # add points and names of cities points(x=data$long, y=data$lat, col="slateblue", cex=2, pch=20) text(rownames(data), x=data$long, y=data$lat, col="slateblue", cex=1, pos=4)
rcombinePlot
# add every connections: for(i in 1:nrow(all_pairs)){ plot_my_connection(all_pairs$long1[i], all_pairs$lat1[i], all_pairs$long2[i], all_pairs$lat2[i], col="skyblue", lwd=1) } # add points and names of cities points(x=data$long, y=data$lat, col="slateblue", cex=2, pch=20) text(rownames(data), x=data$long, y=data$lat, col="slateblue", cex=1, pos=4)
circleConnectionPlot
# Circles for cities points(x=data$long, y=data$lat, col="slateblue", cex=3, pch=20) # Connections plot_my_connection(Paris[1], Paris[2], Melbourne[1], Melbourne[2], col="slateblue", lwd=2) plot_my_connection(Buenos_aires[1], Buenos_aires[2], Melbourne[1], Melbourne[2], col="slateblue", lwd=2) plot_my_connection(Buenos_aires[1], Buenos_aires[2], Paris[1], Paris[2], col="slateblue", lwd=2)
adddot&LinePlot
# Dot for cities points(x=data$long, y=data$lat, col="slateblue", cex=3, pch=20) # Compute the connection between Buenos Aires and Paris inter <- gcIntermediate(Paris, Buenos_aires, n=50, addStartEnd=TRUE, breakAtDateLine=F) # Show this connection lines(inter, col="slateblue", lwd=2)
connectionMap1Plot
getGreatCircle <- function(userLL,relationLL){ tmpCircle = greatCircle(userLL,relationLL, n=200) start = which.min(abs(tmpCircle[,1] - data.frame(userLL)[1,1])) end = which.min(abs(tmpCircle[,1] - relationLL[1])) greatC = tmpCircle[start:end,] return(greatC) }
WorldImageryHTML
# Background 2: World Imagery m <- leaflet() %>% addTiles() %>% setView( lng = 2.34, lat = 48.85, zoom = 3 ) %>% addProviderTiles("Esri.WorldImagery") m
nasaHTML
# Background 1: NASA m <- leaflet() %>% addTiles() %>% setView( lng = 2.34, lat = 48.85, zoom = 5 ) %>% addProviderTiles("NASAGIBS.Night2012") m
leafletHTML
# Load the library library(leaflet) # Initialize the leaflet map with the leaflet() function m <- leaflet() # Then we Add default OpenStreetMap map tiles m <- addTiles(m) m # Same stuff but using the %>% operator m <- leaflet() %>% addTiles() m
mapDataPlot
# help(package='mapdata') map('japan',col="black", lwd=1, mar=rep(0,4)) map('china',col="#69b3a2", lwd=1, mar=rep(0,4)) #map('america',col="black", lwd=1, mar=rep(0,4)) help(packages='mapdata')
MapAustraliaPlot
# Load library library(oz) # Check all available geospatial objects: # help(package='oz') # Map of Australia par(mar=rep(0,4)) oz( states=TRUE, col="#69b3a2")
mapAppPlot
lwd=0.05, mar=rep(0,4),border=1, ylim=c(-80,80) ) # Load library install.packages("mapdata") # Map of Japan: map('japan',col="black", lwd=1, mar=rep(0,4)) help(packages='mapdata')
mapdataPlot
# Load library library(mapdata) # Check all available geospatial objects: # help(package='mapdata') # Map of Japan: map('japan',col="black", lwd=1, mar=rep(0,4) )
persprotPlot
quak.dens <- kde2d(x=quakes$long,y=quakes$lat,n=50) persprot(x=quak.dens$x,y=quak.dens$y, z=quak.dens$z,border="red3",shade=0.4, ticktype="detailed",xlab="Longitude",ylab="Lati", zlab="Kernel estimate")
colorPerspPlot
persp(chor.dens.WIN$x,chor.dens.WIN$y, chor.dens.WIN$z, border=NA, col=rbow[zf.colors],theta=-30,phi=30, scale=FALSE,expand=750,xlab="Eastings (km)", ylab="Northings (km)",zlab="Kernel estimate") colorlegend(col=rbow, zlim=range (chor.dens.WIN$z,na.rm=TRUE), zval=seq(0,0.02,0.0025),main="KDE", digit=4,posx=c(0.85,0.87),posy=c(0.2,0.8))
carperspPlot
persp(x=hp.seq,y=wt.seq,z=car.pred.mat, theta=40,phi=30,ticktype="detailed", xlab="Horsepower",ylab="Weight", zlab="mean MPG") persp(x=hp.seq,y=wt.seq,z=car.pred.mat, theta=40,phi=30,ticktype="detailed", shade=0.6,border=NA,expand=0.8, xlab="Horsepower",ylab="Weight", zlab="mean MPG")
perspPlot
persp(x=hp.seq,y=wt.seq,z=car.pred.mat, theta=-30,phi=23, xlab="Horsepower",ylab="Weight", zlab="mean MPG")
perspectivePlot
hp.seq <- seq(min(mtcars$hp),max(mtcars$hp), length=len) wt.seq <- seq(min(mtcars$wt),max(mtcars$wt), length=len) hp.wt <- expand.grid(hp=hp.seq,wt=wt.seq) car.pred.mat <- matrix(predict(car.fit,newdata=hp.wt), nrow=len,ncol=len) persp(x=hp.seq,y=wt.seq,z=car.pred.mat)
shapecolorlegendPlot
#shape package for colorlegend par(mar=c(5,4,4,7)) image(chor.dens.WIN$x, chor.dens.WIN$y, chor.dens.WIN$z, col=rbow,xlab="Eastings", ylab="Northings",bty="l",asp=1) plot(chor.WIN,lwd=2,add=TRUE) colorlegend(col=rbow,zlim=range (chor.dens.WIN$z,na.rm=TRUE), zval=seq(0,0.02,0.0025),main="KDE", digit=4,posx=c(0.85,0.87))
insideowinPlot
chor.dens.WIN <- kde2d(chorley$x,chorley$y,n=256, lims=c(WIN.xr,WIN.yr)) image(chor.dens.WIN$x,chor.dens.WIN$y, chor.dens.WIN$z,col=rbow) plot(chor.WIN,add=TRUE) inside.owin(x=c(355,345), y=c(420,415),w=chor.WIN)
chordensPlot
chor.dens <- kde2d(x=chorley$x,y=chorley$y,n=256) rbow <- rainbow(200,start=0,end=5/6) image(x=chor.dens$x,y=chor.dens$y, z=chor.dens$z,col=rbow)
rbowPlot
chor.dens <- kde2d(x=chorley$x,y=chorley$y,n=256) rbow <- rainbow(200,start=0,end=5/6) image(x=chor.dens$x,y=chor.dens$y, z=chor.dens$z,col=rbow)
spatstatcholyPlot
chor.dens <- kde2d(x=chorley$x,y=chorley$y,n=256) rbow <- rainbow(200,start=0,end=5/6) image(x=chor.dens$x,y=chor.dens$y, z=chor.dens$z,col=rbow)
spatstatPlot
chor.dens <- kde2d(x=chorley$x,y=chorley$y,n=256) rbow <- rainbow(200,start=0,end=5/6) image(x=chor.dens$x,y=chor.dens$y, z=chor.dens$z,col=rbow)
cyanpixelPlot
blues<-colorRampPalette (c("cyan","navyblue")) par(mar=c(5,4,4,5)) image(hp.seq,wt.seq, car.pred.mat,col=blues(10), xlab="Horsepower",ylab="Weight") colorlegend(col=blues(10), zlim=range(car.pred.mat), zval=seq(10,30,5), main="Mean\nMPG")
pixelimagePlot
The built-in image function plots pixel images. Much as with contour,you supply your x- and y-axis coordinates with z-matrix. image(x=1:nrow(volcano), y=1:ncol(volcano), z=volcano,asp=1)
aphaPlot
filled.contour(x=quak.dens$x,y=quak.dens$y, z=quak.dens$z,color.palette=topo.colors, nlevels=30,xlab="Longitude",ylab="Latitude", key.title=title(main="KDE",cex.main=0.3), plot.axes={axis(1);axis(2); points(quakes$long,quakes$lat,cex=0.5, col=adjustcolor("black",alpha=0.1))})
filldensPlot
filled.contour(x=quak.dens$x,y=quak.dens$y, z=quak.dens$z,color.palette=topo.colors, nlevels=30,xlab="Longitude", ylab="Latitude",key.title=title(main="KDE", cex.main=0.8),plot.axes={axis(1);axis(2); points(quakes$long,quakes$lat,cex=0.5, col=adjustcolor("black",alpha=0.3))})
quakdensPlot
contour(quak.dens$x,quak.dens$y, quak.dens$z, add=TRUE,levels=quak.levs, drawlabels=FALSE,lty=4:1,lwd=2)
Plot
quak.dens <- kde2d(x=quakes$long, y=quakes$lat,n=100) contour(quak.dens$x,quak.dens$y, quak.dens$z) contour(quak.dens$x,quak.dens$y, quak.dens$z, nlevels=50,drawlabels=FALSE,xaxs="i", yaxs="i",xlab="Longitude",ylab="Latitude") points(quakes$long,quakes$lat,cex=0.7)
Plot
quak.dens <- kde2d(x=quakes$long, y=quakes$lat,n=100) contour(quak.dens$x,quak.dens$y, quak.dens$z) contour(quak.dens$x,quak.dens$y, quak.dens$z,nlevels=50,drawlabels=FALSE, xaxs="i",yaxs="i",xlab="Longitude",ylab="Lati") points(quakes$long,quakes$lat,cex=0.7)
contourPlot
Based on a given numeric z-matrix, the R function contour is what’s usedto produce the contours connecting x-y coordinates that share the samez value. contour(x=1:nrow(volcano), y=1:ncol(volcano), z=volcano,asp=1)
farawayPlot
diab<-na.omit(diabetes[, c("chol","weight","gender","frame", "age","height","location")]) ggplot(diab,aes(x=age,y=chol)) + geom_point(aes(shape=location, size=weight,col=height)) + facet_grid(gender~frame) + geom_smooth(method="lm") + labs(y="cholesterol")
facetGirdHPlot
ggp + facet_grid(Month~.)
gridfacetPlot
.~ggp <- ggplot(data=air,aes(x=Temp,fill=Month)) + geom_density(alpha=0.4) + ggtitle("Monthly temperature probability densities") + labs(x="Temp (F)",y="Kernel estimate") ggp + facet_wrap(~Month) ggp + facet_wrap(~Month,scales="free") ggp + facet_wrap(~Month,nrow=1) ggp + facet_grid(Month~.)
seperateFacetPlot
ggp <- ggplot(data=air,aes(x=Temp,fill=Month)) + geom_density(alpha=0.4) + ggtitle("Monthly temperature probability densities") + labs(x="Temp (F)",y="Kernel estimate") ggp + facet_wrap(~Month) ggp + facet_wrap(~Month,scales="free")
gridExtraPlot
gg2 <- ggplot(air,aes(x=Solar.R,fill=Month)) + geom_density(alpha=0.4) + labs(x=expression(paste("Solar radiation (",ring(A),")")), y="Kernel estimate")
Plot
ggplot(data=air,aes(x=Temp,fill=Month)) + geom_density(alpha=0.4) + ggtitle("Monthly temperature probability densities") + labs(x="Temp (F)",y="Kernel estimate")
libraryGGallyPlot
qplot(iris[,4],iris[,3],xlab="Petal width", ylab="Petal length", shape=iris$Species)+ scale_shape_manual(values=4:6) + labs(shape="Species") ggpairs(iris,mapping=aes(col=Species), axisLabels="internal")
Plot
qplot(iris[,4],iris[,3],xlab="Petal width",ylab="Petal length", shape=iris$Species) + scale_shape_manual(values=4:6) + labs(shape="Species")
Plot
iris_pch <- rep(19,nrow(iris)) iris_pch[iris$Species=="versicolor"] <- 1 iris_col <- rep("black",nrow(iris)) iris_col[iris$Species=="virginica"] <- "gray"
surfaceHTML
library(plotly) fig <- plot_ly( type = 'surface', contours = list( x = list(show = TRUE, start = 1.5, end = 2, size = 0.04, color = 'white'), z = list(show = TRUE, start = 0.5, end = 0.8, size = 0.05)), x = ~x, y = ~y, z = ~z) fig <- fig %>% layout( scene = list( xaxis = list(nticks = 20), zaxis = list(nticks = 4), camera = list(eye = list(x = 0, y = -1, z = 0.5)), aspectratio = list(x = .9, y = .8, z = 0.2)))
surfaceOpacityHTML
fig <- plot_ly(showscale = FALSE) fig <- fig %>% add_surface(z = ~z) fig <- fig %>% add_surface(z = ~z2, opacity = 0.98) fig <- fig %>% add_surface(z = ~z3, opacity = 0.98) fig
addsurfaceHTML
dim(z) <- c(15,6) z2 <- z + 1 z3 <- z - 1 fig <- plot_ly(showscale = FALSE) fig <- fig %>% add_surface(z = ~z) fig <- fig %>% add_surface(z = ~z2, opacity = 0.98) fig <- fig %>% add_surface(z = ~z3, opacity = 0.98) fig
HTML
library(plotly) # volcano is a numeric matrix that ships with R fig <- plot_ly(z = ~volcano) fig <- fig %>% add_surface() fig
plotly3DHTML
fig <- plot_ly(mtcars, x = ~wt, y = ~hp, z = ~qsec, color = ~am, colors = c('#BF382A', '#0C4B8E')) fig <- fig %>% add_markers() fig <- fig %>% layout(scene = list(xaxis = list(title = 'Weight'), yaxis = list(title = 'Gross horsepower'), zaxis = list(title = '1/4 mile time')))
Plot
library(scatterplot3d) > scatterplot3d(airquality$Solar.R, airquality$Wind, airquality$Temp, highlight.3d=TRUE, col.axis="blue", col.grid= "lightblue", main="Air Quality Data Set", pch=20, xlab= "Solar Radiation", ylab="Wind", zlab="Temp")
Plot
> par(mfrow=c(1,2)) > hist(airquality$Ozone, xlab="Ozone (ppb)", col="blue", main ="Ozone Frequencies") > plot(airquality$Ozone, airquality$Temp, pch=16, col="blue", cex=1.25, xlab="Ozone (ppb)", ylab="Temperature (degrees F)", main="Air Quality - Ozone vs. Temp", cex.axis=1.5) > legend(125,60, legend="May-Sep 1973", col="blue", pch=16, cex=1.0)
mosaicPlot
library(vcd) mosaic(~Class+Sex+Age+Survived, data=Titanic, shade=TRUE, legend=TRUE)
Plot
data(singer, package="lattice") library(ggplot2) ggplot(data=singer, aes(x=height))+ geom_histogram()+ facet_wrap(~voice.part, nrow=4)
Plot
data(singer, package="lattice") library(ggplot2) ggplot(data=singer, aes(x=height, fill=voice.part))+ geom_density()+ facet_grid(voice.part~.)
BubbleChartPlot
ggplot(mtcars, aes(x=wt, y=mpg, size=disp))+ geom_point(shape=21, color="black", fill="cornsilk")+ labs(x="Weight", y="Miles Per Gallon", title="Bubble Chart", size="Engine\nDisplacement")
Plot
xyplot(mpg~wt | cyl * gear, main="Scatter Plots by Cylinders and Gears", xlab="Car Weight", ylab="Miles per Gallon")
Plot
bwplot(cyl~mpg | gear, main="Box Plots by Cylinders and Gears", xlab="Miles per Gallon", ylab="Cylinders")
Plot
bwplot(cyl~mpg | gear, xlab="Miles per Gallon", ylab="Cylinders") xyplot(mpg~wt | cyl * gear, xlab="Car Weight", ylab="Miles per Gallon") cloud(mpg~wt * qsec | cyl, main="3D Scatter Plots by Cylinders") dotplot(cyl~mpg | gear, xlab="Miles Per Gallon") splom(mtcars[c(1, 3, 4, 5, 6)], detach(mtcars)
Plot
library(lattice)attach(mtcars) gear <- factor(gear, levels=c(3, 4, 5),labels=c("3 gears", "4 gears", "5 gears")) cyl <- factor(cyl, levels=c(4, 6, 8),labels=c("4 cylinders", "6 cylinders", "8 cylinders")) densityplot(~mpg,main="Density Plot", xlab="Miles per Gallon") densityplot(~mpg | cyl,xlab="Miles per Gallon")
Plot
library(lattice) graph1 <- histogram(~height | voice.part, data=singer, main="Heights of Choral Singers by Voice Part" ) graph2 <- bwplot(height~voice.part, data=singer) plot(graph1, split=c(1, 1, 1, 2)) plot(graph2, split=c(1, 2, 1, 2), newpage=FALSE)
Plot
xyplot(mpg~disp|transmission, data=mtcars, scales=list(cex=.8, col="red"), panel=panel.smoother, xlab="Displacement", ylab="Miles per Gallon", main="MPG vs Displacement by Transmission Type", sub="Dotted lines are Group Means", aspect=1)
Plot
pairs(~mpg+disp+drat+wt, data=mtcars, main="Basic Scatter Plot Matrix")
Plot
library(corrgram) corrgram(mtcars, order=TRUE, lower.panel=panel.ellipse, upper.panel=panel.pts, text.panel=panel.txt, diag.panel=panel.minmax, main="Corrgram of mtcars data using scatter plots and ellipses")
Plot
library(plotrix) slices <- c(10, 12,4, 16, 8) lbls <- c("US", "UK", "Australia", "Germany", "France") fan.plot(slices, labels=lbls, main="Fan Plot")
Plot
data.1[1:5,1:5] cor_data <- cor(data.1, method="pearson") round(cor_data[1:5,1:5],3) cor_data <- cor(data.1,method="spearman") cor_data <- cor(data.1,method="spearman") round(cor_data[1:5,1:5],3)
timeserisePlot
# Allow Default X Axis Labels ggplot(economics, aes(x=date)) + geom_line(aes(y=returns_perc)) + labs(title="Time Series Chart", subtitle="Returns Percentage from 'Economics' Dataset", caption="Source: Economics", y="Returns %")
violinPlot
g <- ggplot(mpg, aes(class, cty)) g + geom_violin() + labs(title="Violin plot", subtitle="City Mileage vs Class of vehicle", caption="Source: mpg", x="Class of Vehicle", y="City Mileage")
dotplusboxPlot
g <- ggplot(mpg, aes(manufacturer, cty)) g + geom_boxplot() + geom_dotplot(binaxis='y', stackdir='center', dotsize = .5, fill="red") + theme(axis.text.x = element_text(angle=65, vjust=0.6)) + labs(title="Box plot + Dot plot", subtitle="City Mileage vs Class: data", caption="Source: mpg", x="Class of Vehicle", y="City Mileage")
ggthemePlot
library(ggthemes) g <- ggplot(mpg, aes(class, cty)) g + geom_boxplot(aes(fill=factor(cyl))) + theme(axis.text.x = element_text(angle=65, vjust=0.6)) + labs(title="Box plot", subtitle="City Mileage grouped by Class of vehicle", caption="Source: mpg", x="Class of Vehicle", y="City Mileage")
cyanBoxPlot
Box plot is an excellent tool to study the distribution. It can also show the distributions within multiple groups, along with the median, range and outliers if any. library(ggplot2) theme_set(theme_classic()) # Plot g <- ggplot(mpg, aes(class, cty)) g + geom_boxplot(varwidth=T, fill="plum") + labs(title="Box plot", subtitle="City Mileage grouped by Class of vehicle", caption="Source: mpg", x="Class of Vehicle", y="City Mileage")
densityPlot
library(ggplot2) theme_set(theme_classic()) # Plot g <- ggplot(mpg, aes(cty)) g + geom_density(aes(fill=factor(cyl)), alpha=0.8) + labs(title="Density plot", subtitle="City Mileage Grouped by Number of cylinders", caption="Source: mpg", x="City Mileage", fill="# Cylinders")
HistogramFrequPlot
Histogram on a categorical variable would result in a frequency chart showing bars for each category. By adjusting width, you can adjust the thickness of the bars. g <- ggplot(mpg, aes(manufacturer)) g + geom_bar(aes(fill=class), width = 0.5) + theme(axis.text.x = element_text(angle=65, vjust=0.6)) + labs(title="Histogram on Categorical Variable", subtitle="Manufacturer across Vehicle Classes")
HistogramPlot
g + geom_histogram(aes(fill=class), binwidth = .1, col="black", size=.1) + # change binwidth labs(title="Histogram with Auto Binning", subtitle="Engine Displacement across Vehicle Classes")
DistributionPlot
g + geom_histogram(aes(fill=class), bins=5, col="black", size=.1) + # change number of bins labs(title="Histogram with Fixed Bins", subtitle="Engine Displacement across Vehicle Classes")
dumbbellPlot
gg <- ggplot(health, aes(x=pct_2013, xend=pct_2014, y=Area, group=Area)) + geom_dumbbell(color="#a3c4dc", size=0.75, point.colour.l="#0e668b") + scale_x_continuous(label=percent) + labs(x=NULL, y=NULL, title="Dumbbell Chart", subtitle="Pct Change: 2013 vs 2014", caption="Source: https://github.com/hrbrmstr/ggalt") + plot(gg)
slopchartPlot
p <- ggplot(df) + geom_segment(aes(x=1, xend=2, y=`1952`, yend=`1957`, col=class), size=.75, show.legend=F) + geom_vline(xintercept=1, linetype="dashed", size=.1) + geom_vline(xintercept=2, linetype="dashed", size=.1) + scale_color_manual(labels = c("Up", "Down"), values = c("green"="#00ba38", "red"="#f8766d")) + labs(x="", y="Mean GdpPerCap") + # Axis labels xlim(.5, 2.5) + ylim(0,(1.1*(max(df$`1952`, df$`1957`))))
rankingdotPlot
ggplot(cty_mpg, aes(x=make, y=mileage)) + geom_point(col="tomato2", size=3) + # Draw points geom_segment(aes(x=make, xend=make, y=min(mileage), yend=max(mileage)), linetype="dashed", size=0.1) + # Draw dashed lines labs(title="Dot Plot", subtitle="Make Vs Avg. Mileage", caption="source: mpg") + coord_flip()
LollipopRankingPlot
ggplot(cty_mpg, aes(x=make, y=mileage)) + geom_point(size=5) + geom_segment(aes(x=make, xend=make, y=0, yend=mileage)) + labs(title="Lollipop Chart", subtitle="Make Vs Avg. Mileage", caption="source: mpg") + theme(axis.text.x = element_text(angle=65, vjust=0.6))
rankingPlot
library(ggplot2) theme_set(theme_bw()) # Draw plot ggplot(cty_mpg, aes(x=make, y=mileage)) + geom_bar(stat="identity", width=.5, fill="tomato3") + labs(title="Ordered Bar Chart", subtitle="Make Vs Avg. Mileage", caption="source: mpg") + theme(axis.text.x = element_text(angle=65, vjust=0.6))
AreaChartPlot
ggplot(economics[1:100, ], aes(date, returns_perc)) + geom_area() + scale_x_date(breaks=brks, labels=lbls) + theme(axis.text.x = element_text(angle=90)) + labs(title="Area Chart", subtitle = "Perc Returns for Personal Savings", y="% Returns for Personal savings", caption="Source: economics")
DivergingDotPlot
ggplot(mtcars, aes(x=`car name`, y=mpg_z, label=mpg_z)) + geom_point(stat='identity', aes(col=mpg_type), size=6) + scale_color_manual(name="Mileage", + geom_text(color="white", size=2) + labs(title="Diverging ", subtitle="Normalized mileage from ' mtcars': Dotplot") + ylim(-2.5, 2.5) +coord_flip()
LollipopPlot
ggplot(mtcars, aes(x=`car name`, y=mpg_z, label=mpg_z)) + geom_point(stat='identity', fill="black", size=6) + geom_segment(aes(y = 0, x = `car name`, yend = mpg_z, xend = `car name`), color = "black") + geom_text(color="white", size=2) + labs(title="Diverging Lollipop Chart", subtitle="Normalized mileage from 'mtcars': Lollipop") + ylim(-2.5, 2.5) + coord_flip()
DivergingBarPlot
Compare variation in values between small number of items (or categories) with respect to a fixed reference. Diverging bars Diverging Bars is a bar chart that can handle both negative and positive values.
ggCorrplotPlot
# devtools::install_github ("kassambara/ggcorrplot") # Correlation matrix data(mtcars) corr <- round(cor(mtcars), 1) ggcorrplot(corr, hc.order = TRUE, type = "lower", lab = TRUE, lab_size = 3, method="circle", colors = c("tomato2", "white", "springgreen3"), title="Correlogram of mtcars", ggtheme=theme_bw)
Plot
theme_set(theme_bw()) # pre-set the bw theme. g <- ggplot(mpg_select, aes(displ, cty)) + labs(subtitle="mpg: Displacement vs City Mileage", title="Bubble chart") g + geom_jitter(aes(col=manufacturer, size=hwy)) + geom_smooth(aes(col=manufacturer), method="lm", se=F)
countsPlot
# load package and data library(ggplot2) data(mpg, package="ggplot2") # mpg <- read.csv("http://goo.gl/uEeRGu") # Scatterplot theme_set(theme_bw()) # pre-set the bw theme. g <- ggplot(mpg, aes(cty, hwy)) g + geom_count(col="tomato3", show.legend=F) + labs(subtitle="mpg: city vs highway mileage", y="hwy", x="cty", title="Counts Plot")
Plot
theme_set(theme_bw()) # pre-set the bw theme. g <- ggplot(mpg, aes(cty, hwy)) g + geom_jitter(width = .5, size=1) + labs(subtitle="mpg: city vs highway mileage", y="hwy", x="cty", title="Jittered Points")
Plot
g + geom_point() + geom_smooth(method="lm", se=F) + labs(subtitle="mpg: city vs highway mileage", y="hwy", x="cty", title="Scatterplot with overlapping points", caption="Source: midwest")
EncircleScatterPlot
# install 'ggalt' pkg # devtools::install_github("hrbrmstr/ggalt") options(scipen = 999) library(ggplot2) library(ggalt) midwest_select <- midwest[midwest$poptotal > 350000 & midwest$poptotal <= 500000 & midwest$area > 0.01 & midwest$area < 0.1, ]
ScatterPlot
# Scatterplot gg <- ggplot(midwest, aes(x=area, y=poptotal)) + geom_point(aes(col=state, size=popdensity)) + geom_smooth(method="loess", se=F) + xlim(c(0, 0.1)) + ylim(c(0, 500000)) + labs(subtitle="Area Vs Population", y="Population", x="Area", title="Scatterplot", caption = "Source: midwest") plot(gg)
Plot
clustering example
Plot
library(lattice) n <- seq(5, 45, 5) x <- rnorm(sum(n)) y <- factor(rep(n, n), labels=paste("n =", n)) densityplot(~ x | y, panel = function(x, ...) { panel.densityplot(x, col="DarkOliveGreen", ...) panel.mathdensity(dmath=dnorm, args=list(mean=mean(x), sd=sd(x)), col="darkblue") })
Plot
d=dist(Fintech) hc1=hclust(d,method="ward.D2") #Sum of Squares of Deviations hc2=hclust(d,method="single") #Shortest distance method hc3=hclust(d,method="complete") #Lonest distance method hc4=hclust(d,method="median") #Middle distance method
Plot
opar=par(mfrow=c(2,2)) #Divide Plotting Area plot(hc1,hang=-1);plot(hc2,hang=-1); plot(hc3,hang=-1);plot(hc4,hang=-1) par(opar) #Release Plotting Area
Plot
library(corrplot) corrplot(cor_data) corrplot(cor_data, method="pie",title="method=pie") corrplot(cor_data, type="upper",title="type=upper") corrplot.mixed(cor_data,lower="ellipse",upper="pie")
PlotDiablo1
MyResult.diablo <- block.splsda(X, Y,keepX=list.keepX) plotIndiv(MyResult.diablo, ind.names = FALSE, legend=TRUE, cex=c(1,2,3), title = 'BRCA with DIABLO') plotVar(MyResult.diablo, var.names =c(FALSE, FALSE, TRUE), legend=TRUE, pch=c(16,16,1)) plotDiablo(MyResult.diablo, ncomp = 1) plotDiablo(MyResult.diablo, ncomp = 1)
PlotDiablo
plotVar(MyResult.diablo, var.names =c(FALSE, FALSE, TRUE), legend=TRUE, pch=c(16,16,1))
PlotTCGA
data(breast.TCGA) MyResult.diablo <- block.splsda(X, Y,keepX=list.keepX) plotIndiv(MyResult.diablo, ind.names = FALSE, legend=TRUE, cex=c(1,2,3), title = 'BRCA with DIABLO')
PlotMAE
list.keepX <- c(2:10, 15, 20) # tuning based on MAE set.seed(30) # for reproducbility in thisvignette, otherwise increase nrepeat tune.spls.MAE <- tune.spls(X, Y, ncomp =3, test.keepX =list.keepX, validation ="Mfold", folds = 5, nrepeat = 10,progressBar = FALSE, measure = 'MAE') plot(tune.spls.MAE, legend.position = 'topright')
Plotnetwork
network(MyResult.spls, comp = 1)# network(MyResult.spls,comp = 1, cutoff = 0.6, save = 'jpeg', name.save = 'PLSnetwork')
PlotArrow
plotArrow(MyResult.spls, group=nutrimouse$diet, legend = TRUE, X.label = 'PLS comp 1', Y.label = 'PLS comp 2')
PlotsPLS
plotIndiv(MyResult.spls, group =nutrimouse$genotype, rep.space = "XY-variate", legend = TRUE, legend.title = 'Genotype', ind.names = nutrimouse$diet, title = 'Nutrimouse: sPLS')
Plotnutrimouse
data(nutrimouse) X <- nutrimouse$gene Y <- nutrimouse$lipid MyResult.spls <- spls(X,Y, keepX = c(25,25), keepY = c(5,5)) plotIndiv(MyResult.spls)
PlotSrbct
data(srbct) X <- srbct$gene Y <- srbct$class MyResult.splsda <- splsda(X, Y, keepX =c(50,50)) plotIndiv(MyResult.splsda)
PlotVar
plotVar(MyResult.spca, cex = 1)
Plotmyr2
MyResult.spca <- spca(X, ncomp = 3,keepX = c(15,10,5)) # 1Run the method plotIndiv(MyResult.spca, group =liver.toxicity$treatment$Dose.Group, #2 Plot the samples pch = as.factor(liver.toxicity$treatment$Time.Group), legend = TRUE, title = 'Liver toxicity: genes, sPCA comp 1 - 2', legend.title = 'Dose', legend.title.pch = 'Exposure')
Plotmyr
plotLoadings(MyResult.pca, ndisplay = 100, comp=2, name.var = liver.toxicity$gene.ID[, "geneBank"], size.name = rel(0.3))
Plotpca
plotLoadings(MyResult.pca)
PlotBiocManager
plotIndiv(MyResult.pca, ind.names = FALSE, group = liver.toxicity$treatment$Dose.Group, pch = as.factor(liver.toxicity$treatment$Time.Group), legend = TRUE, title = 'Liver toxicity: genes, PCA comp 1 - 2', legend.title = 'Dose', legend.title.pch = 'Exposure')
PlotBubble
library(mixOmics) data(liver.toxicity) X <- liver.toxicity$gene MyResult.pca <- pca(X) plotIndiv(MyResult.pca, group =liver.toxicity$treatment$Dose.Group, legend = TRUE)
PlotDecisionTree
# Load the party package. It will automatically load other # dependent packages. library(party) # Create the input data frame. input.dat <- readingSkills[c(1:105),] # Give the chart file a name. png(file = "decision_tree.png") # Create the tree. output.tree <- ctree( nativeSpeaker ~ age + shoeSize + score, data = input.dat) # Plot the tree. plot(output.tree) # Save the file. dev.off()
Plotting
3 plotting system
Plot
library(quantmod) getSymbols("ZM",src="yahoo") chartSeries(ZM,subset = "2019-07-01::2020-12-28") addATR() addBBands(n=14,sd=2) addCCI()#SPSS Index addWPR()#William Index addSAR()#stopandReverse index addDPO()#RangFlctuateIndex addRSI()#CompareSW Index
StocPricePrediction
library(quantmod) getSymbols("BTC/USDT",src="yahoo") chartSeries(BTC/USDT,subset = "2019-07-01::2020-12-28") addATR() addBBands(n=14,sd=2) addCCI()#SPSS Index addWPR()#William Index addSAR()#stopandReverse index addDPO()#RangFlctuateIndex addRSI()#CompareSW Index
Reproductive and Replication
## R Markdown This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>. When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document.
Reproductive and Replication
## R Markdown This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>. When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document.
Report
Markdown
Plot
library(quantmod) getSymbols("BTC/USDT",src="yahoo") chartSeries(BTC/USDT,subset = "2019-07-01::2020-12-28") addATR() addBBands(n=14,sd=2) addCCI()#SPSS Index addWPR()#William Index addSAR()#stopandReverse index addDPO()#RangFlctuateIndex addRSI()#CompareSW Index
Plot
#Expandable time series xts library(xts) data(sample_matrix) # TestDataSet smple_matrix head(sample_matrix) plot(sample_matrix) plot(as.xts(sample_matrix)) plot(as.xts(sample_matrix), type='c')
Plot
library(lattice) n <- seq(5, 45, 5) x <- rnorm(sum(n)) y <- factor(rep(n, n), labels=paste("n =", n)) densityplot(~ x | y, panel = function(x, ...) { panel.densityplot(x, col="DarkOliveGreen", ...) panel.mathdensity(dmath=dnorm, args=list(mean=mean(x), sd=sd(x)), col="darkblue") })
Plot
getSymbols("MSFT",src="yahoo") chartSeries(MSFT,subset = "2019-07-01::2020-12-31",theme = "white") addATR()#CompareSW Index addBBands(n=14,sd=2) addCCI()#SPSS Index addWPR()#William Index addSAR()#stopandReverse index addDPO()#RangFlctuateIndex
Plot
getSymbols("AMZN",src="yahoo") chartSeries(AMZN,subset = "2019-07-01::2020-12-28", theme = "white") addATR() addBBands(n=14,sd=2) addCCI()#SPSS Index addWPR()#William Index addSAR()#stopandReverse index addDPO()#RangFlctuateIndex addRSI()#CompareSW Index
Plot
#AMZNCase library(quantmod) getSymbols("AMZN",src="yahoo") chartSeries(AMZN,subset = "2019-07-01::2020-12-28") addATR() addBBands(n=14,sd=2) addCCI()#SPSS Index addWPR()#William Index addSAR()#stopandReverse index addDPO()#RangFlctuateIndex addRSI()#CompareSW Index
Plot
opar=par(mfrow=c(2,2)) #Divide Plotting Area plot(hc1,hang=-1);plot(hc2,hang=-1); plot(hc3,hang=-1);plot(hc4,hang=-1) par(opar) #Release Plotting Area
Plot
index heat caffeine Na price 1 207.2 3.3 15.5 2.8 2 36.8 5.9 12.9 3.3 3 72.2 7.3 8.2 2.4 4 36.7 0.4 10.5 4.0 5 121.7 4.1 9.2 3.5 6 89.1 4.0 10.2 3.3 7 146.7 4.3 9.7 1.8 8 57.6 2.2 13.6 2.1 9 95.9 0.0 8.5 1.3 10 199.0 0.0 10.6 3.5 11 49.8 8.0 6.3 3.7 12 16.6 4.7 6.3 1.5 13 38.5 3.7 7.7 2.0 14 0.0 4.2 13.1 2.2 15 118.8 4.7 7.2 4.1 16 107.0 0.0 8.3 4.2
Plot
#add coefficiency ggcorrplot(cor_data,hc.order=TRUE, outline.color="white",type="lower",colors = c("#6D9EC1", "white", "#E46726"),lab = TRUE) ggcorrplot(cor_data,hc.order=TRUE, outline.color="white",type="lower",colors = c("#6D9EC1", "white", "#E46726"),p.mat = cor_p)
Plot
ggcorrplot(cor_data,hc.order=TRUE, outline.color="white",type="lower") ##change color ggcorrplot(cor_data,hc.order=TRUE, outline.color="white",type="lower",colors = c("#6D9EC1", "white", "#E46726")) ##change theme ggcorrplot(cor_data,hc.order=TRUE, outline.color="white",type="lower",colors = c("#6D9EC1", "white", "#E46726"), ggtheme = ggplot2::theme_void())
Plot
library(ggcorrplot) ##calculate pValue cor_p <- cor_pmat(cor_data) round(cor_p[1:5,1:5],3) ##default square ggcorrplot(cor_data) ggcorrplot(cor_data,method="circle") ggcorrplot(cor_data,hc.order=TRUE, outline.color="white")
Plot
corrplot(cor_data,method="color",order="hclust", addrect=4, col=col1(100), tl.col="black",addCoef.col="grey", addCoefasPercent=T)
Plot
> col1 <- colorRampPalette(c("blue","white","red")) > corrplot(cor_data,order="hclust",addrect=4, + col=col1(100), + bg="khaki1",addgrid.col="green", + tl.col="purple",tl.cex=0.7)
Plot
#hclust.method = c("complete", "ward", "single", "average", #"mcquitty", "median", "centroid") corrplot(cor_data,order="hclust", hclust.method="average", addrect=4) corrplot(cor_data,order="AOE")
Plot
##order #"original", "AOE", "FPC", "hclust", "alphabet" #hclust: #addrect=4 #rect.col = "black" #rect.lwd = 2 #hclust.method = c("complete", "ward", "single", "average", #"mcquitty", "median", "centroid") corrplot(cor_data,order="hclust", hclust.method="average",addrect=4)
Plot
corrplot.mixed(matrix,lower="number", upper="circle") #tl.collower.colnumber.cex corrplot.mixed(cor_data,lower="number", upper="pie", tl.col="red",lower.col="skyblue",number.cex=1)
Plot
cor(x,y=NULL,use="everything",method= c("pearson","kendall","spearman")) cor(x, use='everything', method='pearson') cor(mtcars$mpg, mtcars$cyl) corrplot.mixed(cor_data,lower="number", upper="pie", tl.col="green", lower.col="skyblue",number.cex=1)
Plot
corrplotExample #"circle", "square", "ellipse", "number", "shade", "color", "pie" corrplot(cor_data, method="pie",title="method=pie")
Plot
corrplot(corr, method = c("circle", "square", "ellipse", "number", "shade", "color", "pie"), type = c("full", "lower", "upper"), add = FALSE, col = NULL, bg = "white", title = "", is.corr = TRUE, diag = TRUE, outline = FALSE, mar = c(0,0,0,0), addgrid.col = NULL, addCoef.col = NULL, addCoefasPercent = FALSE
corPlot
corrplot(corr, method = c("circle", "square", "ellipse", "number", "shade", "color", "pie"), addCoef.col = NULL, addCoefasPercent = FALSE, order = c("original", "AOE", "FPC", "hclust", "alphabet"), plotCI = c("n","square", "circle", "rect"), lowCI.mat = NULL, uppCI.mat = NULL, ...)