legend

Remove grey from legend in ggplot2

自古美人都是妖i 提交于 2019-12-11 03:13:41
问题 I would like to remove the grey (which is there because of the SE from geom_smooth) from the legend boxes. I would like to keep the SE in the actual plot though. So in the legend boxes, I just want the color of the lines, not the shadings. Here is an example: library(ggplot2) x <- rnorm(100) y <- rnorm(100) g_ <- sample(c("group1", "group2"), 100, replace = TRUE) ggplot(data.frame(x, y, g_), aes(x = x, y = y, color = g_)) + geom_smooth() 回答1: Here's a way. First, draw lines with confidence

Removing Labels from Legend in ggplot2

瘦欲@ 提交于 2019-12-11 03:12:26
问题 I have the data frame below that I have graphed as shown. How can I limit the values shown in the legend to only the first three? In other words, I want it to only show "A", "B", and "C". graph_table <- read.table(header=TRUE, text=" names freq rank percs sums sums_str 1 A 1208 'Top 3' 46.1 61.1 61.1% 2 B 289 'Top 3' 11.0 61.1 61.1% 3 C 105 'Top 3' 4.0 61.1 61.1% 4 D 388 D 14.8 14.8 14.8% 5 E 173 E 6.6 6.6 6.6% 6 F 102 F 3.9 3.9 3.9% 7 G 70 G 2.7 2.7 2.7% 8 H 54 H 2.1 2.1 2.1% 9 I 44 I 1.7 1

ggplot2 cross effect on legend

陌路散爱 提交于 2019-12-11 03:02:02
问题 I'm trying to plot two normal distributions and two vlines indicating the means. When I do so with ggplot2, the legend becomes a cross, making it hard to see that one of them is a dashed line. ggplot(data = data.frame(x = c(-1, 6)), aes(x)) + stat_function(fun = dnorm, n = 100, args = list(mean = 2, sd = 1), aes(linetype = "a")) + stat_function(fun = dnorm, n = 100, args = list(mean = 3, sd = 1), aes(linetype = "b")) + scale_linetype_manual("Density Function", values = c(1, 2)) + labs(x =

Labelling and theme of ggalluvial plot in R

百般思念 提交于 2019-12-11 02:34:50
问题 For the past hours I have tried to understand the whole design/theme/labelling concept around ggalluvial , but I failed. Within minutes I was able to produce the kind of graph I want (thanks to the package ggalluvial), but I can't figure how to produce the correct labelling/theme I'd like to have. This is where I am currently: This is where I was initially: To get you to understand where I am, here's a reproducible example I used the following code: library(ggalluvial) ds <- as.data.frame

Legend ggplot figure doesn't show for means, errorbars and coloured rectangle

懵懂的女人 提交于 2019-12-11 02:33:44
问题 I have been making this scatterplot of means in R and I know I should include all variables of interest as an aesthetic in the figure plot. However, in the figure that I created (see below), the legend doesn't show. The variables that I'm interested in are the means, errorbars and the coloured rectangles. Anyone knows how to plot them in a smart or manual manner? df <- data.frame(weeks = c(-1, 0, 1, 2, 3, 4), mean = c(64, 65, 66, 66, 66, 67), lowerCI = c(63.4, 64.9, 64.5, 63.8, 62.1, 66.8),

ggplot Legend Bar and Line in Same Graph

谁都会走 提交于 2019-12-11 02:32:08
问题 I'm plotting a bar graph and a line graph on the same chart, and I was wondering if there was a way to have the legend for ggplot say that the bar is for one thing, and the line is for another. That is, rather than identifying what they fill by, which is what I know how to do, have something that says "line = tomatoes", "bar = potatoes". Data: x <- c(0:10) y1 <- c(0,.5,1,1.5,2,2.5,3,3.5,4,4.5,5) y2 <- append(c(1:5),c(6,8,10,12,14,16)) mydata <- as.data.frame(cbind(x,y1,y2)) 回答1: x=c(0:10) See

Legend control with two data frames of different x-scales and different geoms in ggplot2

和自甴很熟 提交于 2019-12-11 02:08:24
问题 Could someone explain to me on how to get full control over the legends in ggplot2 with two data frames with different x-scales presented in two different geoms. The 'name1' and 'name2' is a function that are created with other filtering function. 1. Why geom_point shape appears in the legend for "Group 1"? I expect the legend will show only colour in Group1 and shape for Group2. Is it possible to rearrange the legends as well? i.e Group2 appears first in the row. df1 <- data.frame(g1 = c("a"

Legend disappaers when plotting in R

浪尽此生 提交于 2019-12-11 01:48:07
问题 I have plotted five graphs and a legend. The graphs work just fine, however the legens disappears without an error. My preview in RStudio looks like this When I zoom in, the area where the legend should be is blank. I use the following code: opar <- par (no.readonly = TRUE) par (mfrow = c(3, 2)) library(deSolve) # Plot A LotVmod <- function (Time, State, Pars) { with(as.list(c(State, Pars)), { dx = (b*x) - (b*x*x/K) - (y*(x^k/(x^k+C^k)*(l*x/(1+l*h*x)))) dy = (y*e*(x^k/(x^k+C^k)*(l*x/(1+l*h*x)

R Side-by-side grouped boxplot

匆匆过客 提交于 2019-12-11 01:44:23
问题 I have temporal data of gas emissions from two species of plant, both of which have been subjected to the same treatments. With some previous help to get this code together [edit]: soilflux = read.csv("soil_fluxes.csv") library(ggplot2) soilflux$Treatment <- factor(soilflux$Treatment,levels=c("L-","C","L+")) soilplot = ggplot(soilflux, aes(factor(Week), Flux, fill=Species, alpha=Treatment)) + stat_boxplot(geom ='errorbar') + geom_boxplot() soilplot = soilplot + labs(x = "Week", y = "Flux (mg

Matlab multiple legends on one plot 2014b

牧云@^-^@ 提交于 2019-12-11 01:14:14
问题 I want to have multiple legends on one plot. This solution works perfectly before 2014b version. I am trying to figure out how to make this elegantly using handles, but so far no success. Any ideas are welcome. Example in 2013b: x = 1:50; y1 = sin(x/2); y2 = cos(x/2); f = figure(1); pl(1) = plot(x,y1,'g');hold on; pl(2) = plot(x,y2,'r'); h1 = legend('eg1','eg2'); set(h1,'Location','NorthEast') tmp = copyobj(h1,f); h2 = legend(pl,'sin','line'); set(h2,'Location','SouthWest') I do get something