legend

R ggplot2 single line plot with 2 hlines legends

扶醉桌前 提交于 2019-12-13 03:47:54
问题 I have a simple dataframe (WF) that looks like this: head(wf) Date Gals Days GpD GpM 2016-10-21 6.0 1 6.0 186.0 2016-10-22 6.0 1 6.0 186.0 2016-10-23 12.4 1 12.4 384.4 2016-10-24 26.8 1 26.8 830.8 2016-10-25 33.3 1 33.3 1032.3 2016-10-26 28.3 1 28.3 877.3 What I'm trying to do is time series plot Date versus Gals and put a horizontal line for the mean and median. The glitch I'm facing is correctly putting a legend on the plot. My code so far: require(ggplot2) p1<-ggplot(data=wf, aes(Date,

create a manual legend for density plots in R (ggplot2)

寵の児 提交于 2019-12-13 03:24:50
问题 I want to add a legend to my graph. All solutions I found online use scale_color_manual - but it's not working for me. Where is the legend? Here is my code: library(ggplot2) ggplot() + geom_density(aes(x = rnorm(100)), color = 'red') + geom_density(aes(x = rnorm(100)), color = 'blue') + xlab("Age") + ylab("Density") + ggtitle('Age Densities') theme(legend.position = 'right') + scale_color_manual(labels = c('first', 'second'), values = c('red', 'blue')) 回答1: If for some reason you absolutely

Matlab: change order of entries in Figure legend

我只是一个虾纸丫 提交于 2019-12-13 02:26:58
问题 I have a Figure file where I would like to change the order of the entries (e.g., put the first entry as third one). I saved this Figure.fig long time ago so I am not sure if I can recover the original code. Here I show you my plot: I want the legend elements to be in a decreasing order ( as in the picture) but due to a mistake my second entry is referring to the wrong plot (it says "25 years" but the plot is actually referred to the lowest trend, corresponding to the "9 years" trend). Can I

Remove Objects from Legend When You Have Also Used Fit, Matlab

馋奶兔 提交于 2019-12-13 01:58:01
问题 I've plotted data points and fitted an exponential curve between them using 'fit' in Matlab. The problem is that with the fit-function I got the fitted line I wanted to plot, but also extra markers on top of my regular markers. I solved this problem by plotting the wanted markers on top of the unwanted so that they couldn't be seen. Now to the problem. When I want to show the legends those dots are also in there. How can I remove the markers from the legend without removing the fitted line

Legend with Radarchart in loop

爱⌒轻易说出口 提交于 2019-12-13 00:29:01
问题 As part of a loop I am creating several radarcharts. Each chart is a country, the information displayed in the cobweb are data for several years (lines of different colors). I am trying to add a legend which would make it clear which line (color) relates to which year. As far as I could see, the help file on radarchart is silent on this. (I saw the previous post on this matter, but don't think it's applicable since I am here working in a loop). I would be grateful for any hint. Here is the

How to italicize 1 category in a legend in ggplot2

北城余情 提交于 2019-12-12 20:06:43
问题 For my legend in ggplot2 I have 2 categories, how do I italicize only 1 category and not the other? Thanks! 回答1: You can use expression and italic to create italicised text on labels. data("mtcars") library(ggplot2) p <- ggplot(data = mtcars, aes(x = as.factor(am), fill = as.factor(am))) + geom_bar() + scale_fill_discrete("Transmission", breaks = c(0, 1), labels = c("Automatic", expression(italic("Manual")))) p 来源: https://stackoverflow.com/questions/48688404/how-to-italicize-1-category-in-a

Put percent labels next to legend instead of in the slice

二次信任 提交于 2019-12-12 18:10:43
问题 Let me preface this by saying Pie Charts were not my choice, it is a facet of a report that was requested by a supervisor. I have a series of pie charts created from the following code: perpie <- Full_Mod_good %>% split(.$ServiceSite) %>% imap(function(data, site) { data %>% group_by(ServiceSite, InitialType) %>% summarise(count = n()) %>% mutate(share = round(count / sum(count), digits = 2)) %>% ggplot(aes(x = "", y = share, fill = InitialType)) + geom_col(width = 1) + geom_text(aes(label =

Unicode characters in ggplot legend

流过昼夜 提交于 2019-12-12 17:01:47
问题 I am trying to plot some graph using ggplot2 in R and label the legends using unicode characters such as Japanese. The following is my code: ggplot(mtcars, aes(x=mpg, y=wt, colour = 'ああ')) + geom_line() But I end up getting the following plot: The legend is not displayed properly. Could anyone tell me how to fix this? Thank you so much!! 来源: https://stackoverflow.com/questions/39348634/unicode-characters-in-ggplot-legend

JFreeChart - Problem of colors with 2 legends

回眸只為那壹抹淺笑 提交于 2019-12-12 13:37:07
问题 I try to create a customized legend in my chart but something strange happens when I display one or two legends. When I display 2 legends (the old one and the new one), everything is allright, colors are respected in legends and in the graph. But, when I want to display only the new legend, the colors in the legend are respected but the colors in the graph are not respected anymore. This is an example on my issue: You have to comment and decomment a line to see the problem (see comments)

Greek letters in legend in R

大憨熊 提交于 2019-12-12 13:30:43
问题 I want to have three curves on the same plot with different parameter alpha. curve(sin(x), from = 1, to = 3, lty = 1, ylim = c(-1, 1)) curve(sin(2 * x), add = TRUE, lty = 2) curve(sin(3 * x), add = TRUE, lty = 3) legend("topright", legend = expression(paste(alpha, " = ", c(1, 2, 3))), lty = 1:3) In the legend, I want to have three lines with alplha = 1, alpha = 2, alpha = 3. How do I make it correct? 回答1: The better, looped answer comes from here and user20650. Solution with sapply The