Emulate ggplot2 default color palette
What function can I use to emulate ggplot2’s default color palette for a desired number of colors. For example, an input of 3 would produce a character vector of HEX colors with these colors: 4 Answers 4
What function can I use to emulate ggplot2’s default color palette for a desired number of colors. For example, an input of 3 would produce a character vector of HEX colors with these colors: 4 Answers 4
Suppose I have a ggplot with more than one legend. mov <- subset(movies, length != “”) (p0 <- ggplot(mov, aes(year, rating, colour = length, shape = mpaa)) + geom_point() ) I can turn off the display of all the legends like this: (p1 <- p0 + theme(legend.position = “none”)) Passing show_guide = FALSE to geom_point … Read more
I have used the following ggplot command: ggplot(survey, aes(x = age)) + stat_bin(aes(n = nrow(h3), y = ..count.. / n), binwidth = 10) + scale_y_continuous(formatter = “percent”, breaks = c(0, 0.1, 0.2)) + facet_grid(hospital ~ .) + theme(panel.background = theme_blank()) to produce I’d like to change the facet labels, however, to something shorter (like Hosp … Read more
I wonder how to add regression line equation and R^2 on the ggplot. My code is: library(ggplot2) df <- data.frame(x = c(1:100)) df$y <- 2 + 3 * df$x + rnorm(100, sd = 40) p <- ggplot(data = df, aes(x = x, y = y)) + geom_smooth(method = “lm”, se=FALSE, color=”black”, formula = y ~ … Read more
I need to plot a bar chart showing counts and a line chart showing rate all in one chart, I can do both of them separately, but when I put them together, I scale of the first layer (i.e. the geom_bar) is overlapped by the second layer (i.e. the geom_line). Can I move the axis … Read more
This question already has answers here: ggplot2 plot without axes, legends, etc (9 answers) Closed 6 years ago. I need to remove everything on the x-axis including the labels and tick marks so that only the y-axis is labeled. How would I do this? In the image below I would like ‘clarity’ and all of … Read more
I’m trying to keep the legend of one layer (smooth) and remove the legend of the other (point). I have tried shutting off the legends with guides(colour = FALSE) and geom_point(aes(color = vs), show.legend = FALSE). Edit: As this question and its answers are popular, a reproducible example seems in order: library(ggplot2) ggplot(data = mtcars, … Read more
I plot a simple linear regression using R. I would like to save that image as PNG or JPEG, is it possible to do it automatically? (via code) There are two different questions: First, I am already looking at the plot on my monitor and I would like to save it as is. Second, I … Read more
This simple code (and all my scripts from this morning) has started giving me an off center title in ggplot2: Ubuntu version: 16.04 R studio version: Version 0.99.896 R version: 3.3.2 GGPLOT2 version: 2.2.0 I have freshly installed the above this morning to try and fix this… dat <- data.frame( time = factor(c(“Lunch”,”Dinner”), levels=c(“Lunch”,”Dinner”)), total_bill … Read more
A very newbish question, but say I have data like this: test_data <- data.frame( var0 = 100 + c(0, cumsum(runif(49, -20, 20))), var1 = 150 + c(0, cumsum(runif(49, -10, 10))), date = seq(as.Date(“2002-01-01″), by=”1 month”, length.out=100) ) How can I plot both time series var0 and var1 on the same graph, with date on the … Read more