[Solved] Theme for ggplot2 in r

First define a function with the elements that need to be changed as arguments. Set those arguments to defaults in the graph you really like. To change the defaults, pass them on to the function in its calls. library(ggplot2) my_theme <- function(plot_title_size = 30, colour = “black”, size = 20, angle= 0){ theme(plot.title = element_text(family … Read more

[Solved] Using factor levels with geom_rect

I got some help after asking the same question on the comp.lang.r.general mailing list (http://permalink.gmane.org/gmane.comp.lang.r.general/313656). I ended up adding the following: nodelist <- sort(levels(flatdata$value)) and then using geom_rect(aes(ymin=as.Date(“8-Apr-2014″, format=”%d-%b-%Y”), ymax=as.Date(“30-Apr-2014″, format=”%d-%b-%Y”), xmin=which(nodelist==”node004″)-0.5, xmax=which(nodelist==”node004″)+0.5, fill=”red”, alpha=0.25)) solved Using factor levels with geom_rect

[Solved] How could I get a graph have a shade (confidence interval), legend have no a shade [closed]

First I loaded ggplot and added mtcars library to explain. library(ggplot2) cars <- mtcars This is a normal ggplot graph with geom_smooth and the confidence interval. ggplot(cars, aes(x = mpg, y= disp)) + geom_point() + geom_smooth() within geom_smooth is an option se which is your confidence interval. se is default set to TRUE by setting … Read more

[Solved] ploting ggmap with geom Points (lat_long) annotated 1 to19. Points data is in CSVfile

Here is one approach. I created new lat for text annotation using transform in base R. I used geom_text to add the labels you wanted. I used scale_colour_discrete to change the name of the legend. library(ggmap) library(ggplot2) ### Get a map map <- get_map(location=c(lon=34.832, lat=0.852), color=”color”, source=”google”, maptype=”terrain”, zoom=9) ### Create new lat for annotation … Read more

[Solved] In ggplot, how can I plot multiple graphs in the same window? [closed]

The following should work, I have stored your example input as a dataframe called ‘dat’: library(ggplot2) library(cowplot) plt = ggplot(dat, aes(Income_group, percentage)) + geom_bar(stat=”identity”) + facet_grid(Airport ~.) + background_grid(major=”y”, minor = “none”) + panel_border() plt + theme(axis.text.x = element_text(angle = 90, hjust = 1)) 2 solved In ggplot, how can I plot multiple graphs in … Read more

[Solved] plot multiple lines in ggplot

I’ll make some fake data (I won’t try to transcribe yours) first: set.seed(2) x <- data.frame( Date = rep(Sys.Date() + 0:1, each = 24), # Year, Month, Day … are not used here Hour = rep(0:23, times = 2), Value = sample(1e2, size = 48, replace = TRUE) ) This is a straight-forward ggplot2 plot: … Read more

[Solved] Plotting multi histograms in one

You should post the output from dput(Ft_max), that would make it easier for people to load your example. Use functions from the tidyverse package to gather your data in two columns: “key” for the grouping and “values” for the actual values require(tidyverse) Ft_max %>% gather(“key”, “values”) %>% ggplot(aes(x = values, fill = as.factor(key))) + geom_histogram() … Read more

[Solved] R (ggplot2): line with data labels [closed]

You need to combine DATA2 and DATA3 to one vector and create a vector to define your data. library(ggplot2) x1 <- c(0.2, 0.27, 0.4, 0.37, 0.42, 0.45, 0.70) x2 <- c(0.25, 0.32, 0.28, 0.24, 0.20, 0.19, 0.20) data <- data.frame(x = rep(c(1:7), 2), label = rep(c(“x1”, “x2”), each = 7), y = c(x1, x2)) ggplot(data … Read more

[Solved] Fixing r sorting values method

The reason for the observed behavior is the fact, that the factor levels are handled as string. Because of that, the sort is done in an alphabetical order. This results in “100” being before “99” in an ascending order. The workaround was a bit tricky, I have used the stringr package for easier manipulation of … Read more

[Solved] Stacked barplot with percentage in R ggplot2 for categorical variables from scratch

I used solution provided by NelsonGon, but maked it a bit shorter. Besides i always try to avoid of using third party libraries if it’s possible. So the code working for me was: ggplot(df_test,aes(x=factor(genotype),fill=factor(type)))+geom_bar(position=”fill”)+xlab(“Genotype”)+scale_y_continuous(labels=scales::percent_format()) solved Stacked barplot with percentage in R ggplot2 for categorical variables from scratch

[Solved] R script : add a padding to the ymax of the plot with ggplot2

No code to generate your sample data was provided, so I used the code @akrun had used previously: y3 <- matrix(rnorm(5000), ncol = 5) library(tidyverse) as.data.frame(y3) %>% mutate(row = row_number()) %>% # add row to simplify next step pivot_longer(-row) %>% # reshape long ggplot(aes(value, color = name)) + # map x to value, color to … Read more