r-grid

Change line colour and thickness in grid.curve. R

偶尔善良 提交于 2019-12-25 03:00:24
问题 How do I change the colour and thickness of the curve plotted with the grid.curve function? I've tried adding arguments to the function parameters but they're not supported. Can I somehow change the default par()? library(grid) plot.new() #main viewport vp=viewport(x=0.5,y=0.5,width=1, height=1) pushViewport(vp) #Circle grid.circle(x=0.5, y=0.5, r=0.4) grid.curve(0.5,0.9,0.9,0.5,curvature=arcCurvature(90),ncp=10) 回答1: Figured it out! I had to add the argument gp=gpar(col="red",lwd=10). grid

mapping grid.draw npc scale to native

China☆狼群 提交于 2019-12-24 16:58:52
问题 i am creating overlapping labels in a textGrob txt <- rep("Hi there",2) grid.newpage() fg <- frameGrob() tg <- textGrob(label = txt,x = c(0.25,0.4),y=c(0.5,0.5)) fg <- packGrob(fg, tg) grid.draw(fg) then i take the same textGrob and find the text bounds, convertUnit and draw the tight boxes around the text and plot again i get boxes that dont overlap. What is the correct way to define tg_bounds in order to reproduce the overlap? tg_bounds <- function(tg,lab,theta){ bounds <- grid:::grid.Call

Saving a text box to pdf in R

强颜欢笑 提交于 2019-12-24 12:51:23
问题 I am trying to create a bullet-point type list in R, and want to save it in pdf, which successfully resulted in printing the bullet-point list on a window: a = paste0("Starting portfolio value: $", prettyNum(1000000,big.mark=",",scientific=F)) b = "Inflation assumptions of 3% annually" c = "Average annual returns: 6%" d ="Average annual volatility: 7%" text = paste(a, "\n", b, "\n", c, "\n", d, "\n") library(grid) grid.points(x = rep(10,4), y = c(295, 318, 338, 360), pch = 15, gp = gpar(cex =

Common legend for a grid plot

安稳与你 提交于 2019-12-24 09:54:31
问题 In this reproducible example grid plot, 3 plots have 3 fill colours, and z displays with the "col" blue, but in the fourth plot there is only 1 "col", so z displays as red. I want to show only one common legend (which I can do), but I want z to be blue in all four plots. . Is there a simple way to do that? #--------------------- # Reproducible example #--------------------- library(tidyverse) library(ggplot2) library(grid) library(gridExtra) d0 <- read_csv("x, y, col\na,2,x\nb,2,y\nc,1,z") d1

Two font faces in grid.tables

与世无争的帅哥 提交于 2019-12-24 09:09:53
问题 I have created a grid.table object to display a dataframe in PowerBi, below there is my code: library(reshape) library(gridExtra) library(grid) mydf <- data.frame(id = c(1:5), value = c("A","B","C","D","E")) mytheme <- ttheme_default(base_size = 10, core=list(fg_params=list(hjust=0, x=0.01), bg_params=list(fill=c("white", "lightgrey")))) grid.table(mydf,cols = NULL, theme = mytheme, rows = NULL) and this is my output: I would like to style the font of the output so that only the first column

How to arrange plots with shared axes?

删除回忆录丶 提交于 2019-12-24 03:41:37
问题 I am trying to create an arrangement of three scatterplots with shared axes and marginal histograms. This seems like it should be simple, but it's giving me fits. I have tried approaches with gridExtra and gtable, both of which have gotten the general arrangement like I want but with alignments and plot sizes that were off. There are many other posts related to this question and I have experimented with the answers given to many of them, especially answers from @baptiste here and here. The

Save multiple ggplot2 plots as R object in list and re-displaying in grid

六眼飞鱼酱① 提交于 2019-12-24 03:34:09
问题 I would like to save multiple plots (with ggplot2) to a list during a large for-loop. And then subsequently display the images in a grid (with grid.arrange) I have tried two solutions to this: 1 storing it in a list, like so: pltlist[["qplot"]] <- qplot however for some reason this does save the plot correctly. So I resorted to a second strategy which is recordPlot() This was able to save the plot correctly, but unable to use it in a grid. Reproducable Example: require(ggplot2);require(grid)

Error package grid does not have a namespace

跟風遠走 提交于 2019-12-24 01:45:55
问题 I'm using R.3.3.1 in RStudio 0.99.903 on a work PC. I'm having the same error message when trying to use both ggplot2 and tidytext: although I managed to install both packages, when i launch them i get this error message: Error : package ‘grid’ does not have a namespace At first i thought this meant grid was missing but i read that it's now part of base so i don't understand why it doesn't load when i run library(grid)... Adding to my confusion is the fact that i can only see gridBase and

Error package grid does not have a namespace

不羁的心 提交于 2019-12-24 01:45:11
问题 I'm using R.3.3.1 in RStudio 0.99.903 on a work PC. I'm having the same error message when trying to use both ggplot2 and tidytext: although I managed to install both packages, when i launch them i get this error message: Error : package ‘grid’ does not have a namespace At first i thought this meant grid was missing but i read that it's now part of base so i don't understand why it doesn't load when i run library(grid)... Adding to my confusion is the fact that i can only see gridBase and

How to set the line width to 0.5 pt in ggplot2?

百般思念 提交于 2019-12-24 00:27:38
问题 In ggplot2 , it is easy to use element_text with argument size=6 to set the font size to 6 pt (For text, size has a unit of pt). However, we cannot use element_line with argument size=0.5 to set the line width to 0.5 pt (For line, size has no unit). So how to solve this problem? In grid package, I meet with the similar question. The code is as following: library(grid) grid.rect(width=unit(5, "cm"), height=unit(5, "cm"), gp=gpar(lwd=unit(2, "cm"))) and the result is: Obviously, the line width