Network chord diagram woes in R

I made a bunch of changes to edgebundleR. These are now in the main repo. The following code should get you close to the desired result. live example # devtools::install_github(“garthtarr/edgebundleR”) library(edgebundleR) library(igraph) library(data.table) d <- structure(list(ID = c(“KP1009”, “GP3040”, “KP1757”, “GP2243”, “KP682”, “KP1789”, “KP1933”, “KP1662”, “KP1718”, “GP3339”, “GP4007”, “GP3398”, “GP6720”, “KP808”, “KP1154”, “KP748”, “GP4263”, “GP1132”, … Read more

Add legend to geom_line() graph in r

ggplot needs aes to make a legend, moving colour inside aes(…) will build a legend automatically. then we can adjust the labels-colors pairing via scale_color_manual: ggplot()+ geom_line(data=Summary,aes(y=Y1,x= X,colour=”Y1″),size=1 )+ geom_line(data=Summary,aes(y=Y2,x= X,colour=”Y2″),size=1) + scale_color_manual(name = “Y series”, values = c(“Y1” = “darkblue”, “Y2” = “red”))

ggplot2 plot area margins?

You can adjust the plot margins with plot.margin in theme() and then move your axis labels and title with the vjust argument of element_text(). For example : library(ggplot2) library(grid) qplot(rnorm(100)) + ggtitle(“Title”) + theme(axis.title.x=element_text(vjust=-2)) + theme(axis.title.y=element_text(angle=90, vjust=-0.5)) + theme(plot.title=element_text(size=15, vjust=3)) + theme(plot.margin = unit(c(1,1,1,1), “cm”)) will give you something like this : If you want … Read more

How to plot with a png as background? [duplicate]

Try this: library(png) #Replace the directory and file information with your info ima <- readPNG(“C:\\Documents and Settings\\Bill\\Data\\R\\Data\\Images\\sun.png”) #Set up the plot area plot(1:2, type=”n”, main=”Plotting Over an Image”, xlab=”x”, ylab=”y”) #Get the plot information so the image will fill the plot box, and draw it lim <- par() rasterImage(ima, lim$usr[1], lim$usr[3], lim$usr[2], lim$usr[4]) grid() lines(c(1, … Read more

How to remove or hide y-axis ticklabels from a matplotlib / seaborn plot

seaborn is used to draw the plot, but it’s just a high-level API for matplotlib. The functions called to remove the y-axis labels and ticks are matplotlib methods. After creating the plot, use .set(). .set(yticklabels=[]) should remove tick labels. This doesn’t work if you use .set_title(), but you can use .set(title=””) .set(ylabel=None) should remove the … Read more

ggplot2 multiple scales/legends per aesthetic, revisited [duplicate]

I managed to get a satisfactory result by combining grobs from two separately generated plots. I’m sure the solution can be generalized better to accommodate different grob indices … library(ggplot2) library(grid) pd = data.frame( letters = strsplit(“AGTGACCGACTATCATAGTGACCCAGAATCATAGTGACCGAGTATGAT”, “”)[[1]], species = rep(c(“Human”, “Armadillo”, “Porcupine”), each=16), x = rep(1:16, 3), change = c(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0, 0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0), score1 = … Read more

Saving Matplotlib graphs to image as full screen

The method you use to maximise the window size depends on which matplotlib backend you are using. Please see the following example for the 3 most common backends: import matplotlib.pyplot as plt plt.figure() plt.plot([1,2], [1,2]) # Option 1 # QT backend manager = plt.get_current_fig_manager() manager.window.showMaximized() # Option 2 # TkAgg backend manager = plt.get_current_fig_manager() manager.resize(*manager.window.maxsize()) … Read more

How to make a sunburst plot in R or Python?

Python version of sunburst diagram using matplotlib bars in polar projection: import numpy as np import matplotlib.pyplot as plt def sunburst(nodes, total=np.pi * 2, offset=0, level=0, ax=None): ax = ax or plt.subplot(111, projection=’polar’) if level == 0 and len(nodes) == 1: label, value, subnodes = nodes[0] ax.bar([0], [0.5], [np.pi * 2]) ax.text(0, 0, label, ha=”center”, … Read more