r-grid

Remove colored border around ggplot

若如初见. 提交于 2019-12-01 22:38:38
问题 I am adding ggplots to viewports . Both ggplot and viewport has the same background colour. My problem is that I have a white rectangle surrounding my ggplots and I dont seem to be able to find the option to remove it using theme . Any ideas? library(grid) library(ggplot2) Pie_chart <- ggplot(df , aes(x = "", y = prop_1, fill = rank) ) + geom_bar(stat="identity", width=2) + coord_polar("y", start = 0) + labs(x = NULL, y = NULL, fill = NULL, title = "") + theme(axis.line = element_blank(),

Remove colored border around ggplot

人盡茶涼 提交于 2019-12-01 21:13:05
I am adding ggplots to viewports . Both ggplot and viewport has the same background colour. My problem is that I have a white rectangle surrounding my ggplots and I dont seem to be able to find the option to remove it using theme . Any ideas? library(grid) library(ggplot2) Pie_chart <- ggplot(df , aes(x = "", y = prop_1, fill = rank) ) + geom_bar(stat="identity", width=2) + coord_polar("y", start = 0) + labs(x = NULL, y = NULL, fill = NULL, title = "") + theme(axis.line = element_blank(), axis.text = element_blank(), axis.ticks = element_blank(), legend.position="none")+ theme(plot.margin =

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

拈花ヽ惹草 提交于 2019-12-01 20:38:53
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(plot.margin = unit(c(1.5, 2, 1, 1), 'lines')) # Create plot with color p = ggplot(diamonds,aes(cut,fill

Convert units from npc to native using grid in R

只谈情不闲聊 提交于 2019-12-01 17:24:23
问题 The core of my problem: I'm attempting to convert npc units to native units using the grid package's convertUnit, convertX and convertY functions. (npc=normalized parent coordinates, possibly known as ndc units, normalized device coordinates to some in base graphics R. I'm trying to get to native units, those in which the plot is graphed, so in terms of the xlim and ylim units.) However when I attempt to do this as such: > xyplot(1:10~1:10) > convertX(unit(.9, "npc"), "native") [1] 484

Multicolored title with R

柔情痞子 提交于 2019-12-01 17:06:23
I'd like to add colors to certain words in titles to my graphs. I've been able to find some precedent here . Specifically, I'd like the text that's wrapped in apostrophes (in the output, below) to correspond to the color of their respective bar charts. Here's how far I've gotten with titles in R before having to export a PDF to Adobe Illustrator or other program. name <- c("Peter", "Gabriel", "Rachel", "Bradley") age <- c(34, 13, 28, 0.9) fake_graph <- family[order(family$age, decreasing = F), ] fake_graph <- within(fake_graph, { bar_color = ifelse(fake_graph$name == "Rachel", "blue", "gray")

Multicolored title with R

放肆的年华 提交于 2019-12-01 16:22:37
问题 I'd like to add colors to certain words in titles to my graphs. I've been able to find some precedent here. Specifically, I'd like the text that's wrapped in apostrophes (in the output, below) to correspond to the color of their respective bar charts. Here's how far I've gotten with titles in R before having to export a PDF to Adobe Illustrator or other program. name <- c("Peter", "Gabriel", "Rachel", "Bradley") age <- c(34, 13, 28, 0.9) fake_graph <- family[order(family$age, decreasing = F),

dismantling a ggplot with grid and gtable

拟墨画扇 提交于 2019-12-01 11:15:41
I'm struggling to build a dual-axis plot based on ggplot objects. At baptiste's suggestion, I have broken down the problem into smaller parts. The present issue is: how to remove all of the data from the grobs , while keeping the axis, the axis labels, the axis tickmarks, and the grid lines? By 'data' I mean the data associated with geom_line() and geom_points() . The reason for wanting to do this is that in the process of building a dual-axis plot, I ran into the following problem: the grid lines from one grob would overwrite the data from the other grob. By removing the data lines and points

gtable_add_grob(): linesGrob() not displayed

泄露秘密 提交于 2019-12-01 10:59:41
Why are the lines (via linesGrob ) not drawn in the following plot? require(gtable) base <- gtable(widths=unit(rep(1, 2), "null"), heights=unit(rep(1, 3), "null")) grid.newpage() g <- 1 for(i in 1:3) { for(j in 1:2) { base <- gtable_add_grob(base, grobs=list(linesGrob(x=1:4, y=4:1), rectGrob(gp=gpar(fill="#FF0000")), textGrob(label=g)), i, j, name=1:3) g <- g+1 } } grid.draw(base) Two reasons: the coordinates fall outside the viewport the rectGrob is drawn on top and masks it require(gtable) # let's fix this name before it's too late gtable_add_grobs <- gtable_add_grob base <- gtable(widths

Removing right border from ggplot2 graph

你。 提交于 2019-12-01 09:49:55
With the following code I can remove top and right borders along with other things. I wonder how to remove the right border of the ggplot2 graph only. p <- ggplot(mtcars, aes(x = wt, y = mpg)) + geom_point() p + theme_classic() the theme system gets in the way, but with a little twist you can hack the theme elements, library(ggplot2) library(grid) element_grob.element_custom <- function(element, ...) { segmentsGrob(c(1,0,0), c(0,0,1), c(0,0,1), c(0,1,1), gp=gpar(lwd=2)) } ## silly wrapper to fool ggplot2 border_custom <- function(...){ structure( list(...), # this ... information is not used,

Save plots as R objects and displaying in grid

血红的双手。 提交于 2019-12-01 09:42:28
问题 In the following reproducible example I try to create a function for a ggplot distribution plot and saving it as an R object, with the intention of displaying two plots in a grid. ggplothist<- function(dat,var1) { if (is.character(var1)) { var1 <- which(names(dat) == var1) } distribution <- ggplot(data=dat, aes(dat[,var1])) distribution <- distribution + geom_histogram(aes(y=..density..),binwidth=0.1,colour="black", fill="white") output<-list(distribution,var1,dat) return(output) } Call to