r-grid

Using pch Characters in grid.text

半城伤御伤魂 提交于 2019-12-23 19:23:33
问题 I have created a graph using ggplot2. Now I want to have the legend not onto the graph but in the grid outside the graph. My question is now if someone knows if there is a possibility to use the pch symbols in grid.text? Here is an image to show what I want ;) Best regards 回答1: I don't know if we can directly use points in text, but you can combine grid.text and grid.points: grid.points(x=rep(0.1,9),y=1:9/10,pch=1:10,default.units="npc") grid.text(x=rep(0.2,9),y=1:9/10,label=letters[1:9]

How to use gtable_add_grob() does not 'add'

此生再无相见时 提交于 2019-12-23 18:01:05
问题 Why does the following plot not display the numbers ( g ; specified via textGrob(label=g)) ) in the 6 panels? If I use the text grob only, this also works, but a text grob and a rectangular grob seem to be not so easy. Unfortunately the help page of gtable_add_grob does not give a lot of help... require(gtable) base <- gtable(widths=unit(rep(1, 2), "null"), heights=unit(rep(1, 3), "null")) g <- 1 for(i in 1:3) { for(j in 1:2) { base <- gtable_add_grob(base, list(rectGrob(gp=gpar(fill="

grid.arrange from gridExtras exiting with “only 'grobs' allowed in 'gList'” after update

百般思念 提交于 2019-12-21 06:47:03
问题 I just updated R, R Studio, and a bunch of packages including ggplot2 and gridExtras on my Mac. Now gridExtras is failing in basic plotting with the error: "only 'grobs' allowed in "gList"" Here's some code that should work but does not: library(ggplot2) p1 = qplot(1:10,rnorm(10)) p2 = qplot(1:10,rnorm(10)) library(gridExtra) grid.arrange(p1, p2, ncol=2, main = "Main title") This dumps out the following error: Error in gList(list(grobs = list(list(x = 0.5, y = 0.5, width = 1, height = 1, :

One shared legend for a cowplot grid in R

被刻印的时光 ゝ 提交于 2019-12-20 10:24:16
问题 I just built a grid with package cowplot (to label the plots from A-D). The plots are made with package ggplot2 : pfour<-ggplot(four, aes(x=Concentration, y=Percentage, fill=Phenotype)) + geom_bar(stat='identity',color='black') + scale_fill_grey(start = .4, end = .9) + theme_bw()+ylab("Distribution") + xlab("Contentration [mg/ml]") + ggtitle("96 hpf") + theme(legend.title = element_text(colour="black", size=10, face="bold")) + theme(legend.background = element_rect(fill="white", size=0.5,

Why does 2nd ggplot not appear using knitr and grid?

前提是你 提交于 2019-12-19 20:34:45
问题 I am trying to create a document using knitr that includes ggplot2 plots modified using grid . In the example below, there should be 2 plots both using the diamonds dataset included in ggplot2 : the first one shows cut vs. color and the second shows cut vs. clarity. Instead, the later plot is repeated twice. The first plot is not generated in the figure directory at all. \documentclass{article} \begin{document} <<fig.cap = c('color', 'clarity')>>= library(ggplot2) library(grid) theme_update

538-ify ggplot output: justifying pictureGrob in R grid graphics

烈酒焚心 提交于 2019-12-19 11:43:22
问题 I am trying to write a little utility function that will annotate my plots Reuben Fischer-Baum style with a nice little logo and url at the bottom - eg: I've figured out how to get a postscript file loaded into R; it's justifying the image on the bottom of the plot that's driving me crazy. I can't get the pictureGrob to left justify; at best I can get it to center on the left hand side of my plot, but half of my image gets cut off, like this reproducible example below: Tinkering with the

change the background color of grid.arrange output

自古美人都是妖i 提交于 2019-12-19 09:54:09
问题 I am using grid.arrange from gridExtra package to put two graphs on one page and save it to a png file. I like to change the background colour of the final png file that is produced by grid.arrange . Is it possible? I was not able to come across any info. grid.arrange(p1, p2, main=textGrob("CPU Util", gp=gpar(cex=1.2, fontface="bold", col="#990000")), ncol = 1, clip=TRUE) 回答1: Try setting the bg = argument to png() library(gridExtra) library(lattice) png(bg = "wheat1") grid.arrange(xyplot(1

Side-by-side Venn diagram using Vennerable

梦想的初衷 提交于 2019-12-19 03:38:16
问题 I am trying to put two Venn diagrams in one single graph, i.e. I am using par(mfrow=c(1,2)) at the very beginning. However, when I use the Venn() function in the Vennerable package: VennCompare = Venn(SetNames = c("A", "B", "C"), Weight = c(0, 38, 1, 0, 1, 80, 0, 14)) pdf(file="Venn.pdf", width=12, height=6) par(mfrow=c(1,2)) plot(VennCompare, doWeights=FALSE) plot(VennCompare, doWeights=TRUE, show = list(SetLabels = TRUE, Faces = FALSE)) dev.off() The resultant pdf file contains 2 pages, and

Center-align legend title and legend keys in ggplot2 for long legend titles

六眼飞鱼酱① 提交于 2019-12-17 22:52:17
问题 I am having a hard time making the title of a legend center-aligned relative to the legend keys when the legend title is long. There is a question from a year ago that works for short titles, but it doesn't seem to work for long ones. Example, first with a short legend title: library(ggplot2) ggplot(iris, aes(x=Sepal.Length, y=Sepal.Width, color=Petal.Width)) + geom_point(size = 3) + scale_color_distiller(palette = "YlGn", type = "seq", direction = -1, name = "A") + theme(legend.title.align =

Change text color for cells using TableGrob

橙三吉。 提交于 2019-12-17 16:21:38
问题 Is there a way to individually change the color of the text of a cell when using tableGrob and ggplot2? For instance in the code below it'd be great if the cell with 1 could be blue and the cell with 2 could be red, with 3:8 all black. library(ggplot2) library(grid) mytable = as.table(matrix(c("1","2","3","4","5","6","7","8"),ncol=2,byrow=TRUE)) mytable = tableGrob(mytable,gpar.coretext = gpar(col = "black", cex = 1)) mydf = data.frame(x = 1:10,y = 1:10) ggplot( mydf, aes(x, y)) + annotation