How to change the default font size in ggplot2

I'd like to know if it is possible to change some default parameters of ggplot2 graphics, like font size for instance, for a whole R session. The idea is to avoid setting them for each plot. Use theme_set()theme_set(theme_gray(base_size = 18))qplot(1:10, 1:10) [XXX]Use theme_set if you want to update for the remainder of your active session:theme_set(theme_grey(base_size = 18)) If you only want to change one graph you can set the base_size in the theme:qplot(1:10, 1:10) + theme_grey(base_size = 18) ggplot(mtcars, aes(x = mpg, y = cyl)) + geom_point() +theme_grey(base...

Accurate Venn diagrams using eulerr

I'm trying to use the eulerr package to create Venn diagrams. I have 2 lists that I would like to use to create the Venn diagram with. 1 of the lists is a subset of the first. Strangely, eulerr seems to think that there is one value present in listbthat is unique to that subset. I can't seem to figure out which values it thinks are unique.https://pastebin.com/J7tPcfAt> length(a)[1] 3278> length(b)[1] 1318When I check overlap between the subsets I get the expected results:> length(which(a %in% b))[1] 1318> length(which((b %in% a)))[1] 1318> length(which(!(b %i...

Access names of columns passed to map()

How to access names of input to purrr::map()?This code:library(tidyverse)library(janitor)diamonds %>% select(cut, color) %>% map( function(x) janitor::tabyl(x) ) Outputs this:$cut x n percent1 Fair 1610 0.029847982 Good 4906 0.090952913 Very Good 12082 0.223989624 Premium 13791 0.255672975 Ideal 21551 0.39953652$color x n percent1 D 6775 0.125602522 E 9797 0.181627733 F 9542 0.176900264 G 11292 0.209343725 H 8304 0.153948836 I 5422 0.100519107 J 2808 0.05205784But I am trying to access the names of columns pass...

changing colors of geom_col ggplot2 to show categorical variable at 3 sites

Long time fan of this site, first time user though.Been searching for a similar/working result for this question.I am trying to show the PROPORTION that each level of a 2 level factor appear at three locations. All in a side by side bar chart in ggplot.Here is the code I've been using to (try) to create the chart. The result has been two charts: one using geom_bar and geom_col, respectively. What I'd like is essentially a combination of the two. The first, but with the colors and Y axis of the second.Thank you! ggplot(df,aes(x = Stream,fill = death)) + geom_bar(posit...

ggplot2 bar graph exported to pdf is made up of segments instead of a solid shape

My problem is that when I output a ggplot bar graph as a pdf and import it in illustrator, each bar is made up of many tiny segments rather than being a single solid shape. How can I convert the bars to solid shapes either in illustrator or when exporting in R?R code:library("ggplot2")data(diamonds)gplot <- ggplot(diamonds, aes(cut,carat)) + geom_bar(stat="identity")ggsave("gplot.pdf",gplot)Screenshot of pdf imported into Illustrator: The problem is that geom_bar is using position="stack" to draw all the little bars right next to each other to stack up to the big bar....

create new data frame from a function of other data frames

I’m such a newbie to R that I may have a difficult time asking my question. Please bear with me.I have two data frames. Let’s pretend for the sake of explanation:df1Columns represents types of gains: corn, oats, wheat, etc.Rows represents the month of the year, jan, feb, etc.Elements represents the price per ton for that gain type purchased during that particular month.df2Columns representing countries: Spain, Chile, Mexico, etc.The rows of this frame represent additional costs for dealing with that country, maybe: Packaging cost, Shipping cost, Country import tax, Ins...

Neat formatting for Venn diagram in R with unbalanced group sizes

I'm using the VennDiagram R package to try to generate a neatly formatted diagram comparing two groups. I have successfully used this package in the past to compare relatively similarly-sized groups. However, now I'm comparing groups that have significantly different sizes (# of unique elements in the first group is ~3,600, # of unique elements in the second group is ~60, and # of overlapping elements is ~80).The appearance of my current Venn diagram is that the group with the larger # of elements has this value displayed within its circle, but the labels for the intersecti...

R using rgp symbolicRegression for equation discovery

I am trying to use the package rgp for equations discoverylibrary(rgp)x = c (1:100)y = 5*x+3*sin(x)+4*x^2+75data1 = data.frame(x,y)newFuncSet <- functionSet("+","-","*")result1 <- symbolicRegression(y ~ x, data = data1, functionSet = newFuncSet, stopCondition = makeStepsStopCondition(2000))plot(data1$y, col=1, type="l"); points(predict(result1, newdata = data1), col=2, type="l")model <- result1$population[[which.min(result1$fitnessValues)]]However, I keep getting an error message.I would be grateful for your help in pointing out the errors I have made above....

Assigning continuous fill color to geom_bar

I am generating a bar chart from data that is in the following format:count | month------|-----------1000 | 2012-01-0110000 | 2012-02-01I am trying to assign continuous colors to my bar chart. I want a gradient of colors to be used as the fill color of the bars.I am trying this:ggplot(userData, aes(month, count)) + geom_bar(stat = "identity") + scale_x_date() + # scale_fill_gradient(low="blue", high="red") + scale_fill_continuous(low="blue", high="red", limits=c(0,6500000)) + labs(x= "Time", y="Count")However, I am not getting the desired result and the ba...

ggplot legend list is larger than page

I have a plot in R which has a very large number of sample groups, and therefore the legend is larger than the page size and is cut off. I understand that this is not publication quality, but I need to know the colours to be able to make the legend in Illustrator.Is there a way to make the page size much bigger or somehow change the legend format so that I can include all the keys? The reason for this is so that I can open the PDF in Illustrator and get the colours for each sample to create a new legend that will be for publication. I thought that maybe there is a clippi...

R - Function to create a data.frame containing manipulated data from another data.frame

Hi I am new to R and have a question. I have a data.frame (df) containing about 30 different types of statistics from years 1960-2012 for about 100 different countries. Here is an example of what it looks like: Country Statistic.Type 1960 1961 1962 1963 ... 2012 __________________________________________________________________________________1 Albania Death Rate 10 21 13 24 25 2 Albania Birth Rate 7 15 6 10 9 3 Albania Life Expectancy 8 ...

Best way to replace a nested for loop in R

for loops in R are generally considered slow: it's hard to avoid unintended memory read/writes. But how to replace a nested for loop? Which is the best approach?Please note that this is a generic question: the f function below is just an example, it could be much more complicated or return different objects. I just want to see all the different approaches that one can take in R to avoid nested for loops.Consider this as an example:al <- c(2,3,4)bl <- c("foo", "bar")f <- function(n, c) { #Just one simple example function, could be much more complicated data.frame...

R: change colors across bars in stacked bar chart

Using base graphics, I got a barchart like this onea <- c(1,2,3); b <- c(1,1,1)barplot(rbind(a,b), col=c("red","gray"))with each bar grey at the top and red at the bottom. However, I would like each bar to change the color at the bottom and keep the grey at the top.cols <- c(rbind(c("red","green","blue"),"gray"))barplot(rbind(a,b), col=cols) did not do the trick. Is there any other way? Not the most elegant way but this works.a<-c(1,1,1)b<-c(1,0,0)c<-c(0,2,0)d<-c(0,0,3)cols <-c("red","green","blue","gray")# notice order of rbind... a is lastbarpl...

ggplot2 geom_point 50000 points - output to pdf - need to open in Illustrator

I need to plot 50000 points on a single scatterplot using ggplot2 that I then need to be able to open in Illustrator in vector format (making figures for a paper).There is no better way to display my data than a scatterplot, and I need to be able to show the individual points.At the moment, I am outputting to pdf. The problem is that while I can open the file in Adobe Acrobat and Mac Preview, Illustrator hangs when "Reading PDF file", probably because there are just too many points for it to handle.Should I be outputting to a different graphics device? Or is there a way I c...

Calculating yearly growth-rates from quarterly, long form data in r

My data takes the following form:df <- data.frame(Sector=c(rep("A",8),rep("B",8)), Country = c(rep("USA", 16)), Quarter=rep(1:8,2),Income=20:35)df2 <- data.frame(Sector=c(rep("A",8),rep("B",8)), Country = c(rep("UK", 16)), Quarter=rep(1:8,2),Income=32:47)df <- rbind(df, df2)What I want to do is to calculate the growth rate from the first quarter each year to the first quarter the second year, within country and sector. In the example above it would be the growth rate from quarter 1 to quarter 5. So for Sector A, in the USA, it would ...

Assigning 4 different players to a station by round with no repeats

I am building an r-script that uses all the possible combinations of 4 different variables: Rounds, Stations, and Players (Male and Female). Below is my dput version of the dataset: structure(list(x = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L,...

Page 1 of 536  |  Show More Pages:  Top Prev Next Last