legend

how to remove line from fill scale legend using geom_vline and geom_histogram r ggplot2

柔情痞子 提交于 2019-12-05 19:39:38
Basics: Using R statistical software, ggplot2, geom_vline, and geom_histogram to visualize some data. The issue is with the legend keys. I'm trying to plot a pair of histograms from some stochastic simulations, and on top of that plot a couple of lines representing the result of a deterministic simulation. I've got the data plotted, but the legend keys for the histograms have an unnecessary black line through the middle of them. Can you help me remove those black lines? Some sample code reproducing the issue is here: df1 <- data.frame(cond = factor( rep(c("A","B"), each=200) ), rating = c

Add legend to ggplot histogram with different types of aesthetics

谁都会走 提交于 2019-12-05 19:34:53
I want to add a legend to one of my plots, but I have different aesthetics and I never created a legend so I find it very difficult to determine how to build it. One of my aesthetics is a fill code, which I added manually as a vector. The other aesthetic is a vertical line that I added with geom_vline. From the graph below, there are three characteristics that I want to add to the legend: 1) The bars with color dark blue, 2) The bars with color light blue and 3) The vertical line. Does anyone have a suggestion for me on how to code this efficiently? #df df <- data.frame(Time_Diff <- runif(1000

scale_fill_manual based on another factor in ggplot2

社会主义新天地 提交于 2019-12-05 17:39:31
I am trying to color-code my legend based on a broader categorization of the factor used to "fill" my geom_bar in ggplot2. My plot looks like this: which I got using this R code: ggplot(df, aes(year, TOTALshark, fill=fishery)) + geom_bar(width=.5,stat="identity", position="dodge")+ facet_wrap(~div) Here is a dput sample of my dataset: > dput(smpl) df <- structure(list(X1 = structure(c(6L, 11L, 22L, 27L, 10L, 10L, 6L, 11L, 6L, 10L, 8L, 6L, 6L, 4L, 22L, 18L, 10L, 10L, 11L, 6L ), .Label = c("AMERICAN PLAICE", "BIGEYE TUNA", "BIVALVE", "BLUEFIN TUNA", "CAPELIN", "COD(ATL)", "CRAB(SNOW,QUEEN)",

How to manipulate legend in Incanter chart

烂漫一生 提交于 2019-12-05 17:09:25
I'm trying to include a legend in an Incanter chart, but I'm having some troubles getting what I want: I want to be able to instantiate a chart with no data first (using [] [] as my x y arguments), then add the data points in a separate step. However the only way to add a legend is to specify :legend true after the initial x y points are given in the constructor. Cannot specify :legend true without x y arguments, and I have not found any add-legend function. The legend option captures the code I use when adding the chart data, which means if I don't want ugly code to appear in the legend I

Hide MATLAB legend entries for some graphical objects in plots

两盒软妹~` 提交于 2019-12-05 16:35:12
MATLAB legends list everything in a plot, including guidelines that you have put on a plot. A fudge to get around that is to do *Plot *Add legend *Add guidelines However, MATLAB puts the most recent lines in the front, meaning the guidelines then sit over the displayed data; ugly and distracting. Similar problems occur any time you build up a complicated plot, legend freaks out and grabs everything, and workarounds with plotting order can be ugly Example code: %**** Optional guidelines figure(1) plot([2 2],[0,1],'k--'); hold on %**** DATA N = 4; y=rand(5,N); x=1:1:5; for plotLoop=1:N; %* Plot

Control the number of rows within a legend

被刻印的时光 ゝ 提交于 2019-12-05 13:51:56
问题 I am currently trying to plot a large amount of data on a single plot. I have structured my representation using repeated colors and symbols. However, when plotting the final results, the legend appears slightly off because I cannot control the number of rows within it. Thus, instead of getting 5 repeated green, then 5 repeated red, 5 repeated blue then 2 other, I get 5 -4 -4 -4 (where I would have prefered 5 - 5 - 5 - 2) You can clearly see this in attached image. Right now I use these

Legend with vertical line in matplotlib

百般思念 提交于 2019-12-05 09:53:50
I need to show a vertical line in a matplotlib legend for a specific reason. I am trying to make matplotlib understand that I want a vertical line with the lines.Line2D(x,y) but this is clearly not working. import matplotlib.pyplot as plt from matplotlib import lines fig, ax = plt.subplots() ax.plot([0,0],[0,3]) lgd = [] lgd.append(lines.Line2D([0,0],[0,1], color = 'blue', label = 'Vertical line')) plt.legend(handles = lgd) I need the line to appear vertical, not the legend. Can anyone help? DavidG You can use the vertical line marker when making your line2D object. A list of valid markers can

Manually creating a legend when you can't supply a color aesthetic

别说谁变了你拦得住时间么 提交于 2019-12-05 09:09:35
In attempting to answer this question , one way to create the desired plot was to use geom_dotplot from ggplot2 as follows: library(ggplot2) library(reshape2) CTscores <- read.csv(text="initials,total,interest,slides,presentation CU,1.6,1.7,1.5,1.6 DS,1.6,1.7,1.5,1.7 VA,1.7,1.5,1.5,2.1 MB,2.3,2.0,2.1,2.9 HS,1.2,1.3,1.4,1.0 LS,1.8,1.8,1.5,2.0") CTscores.m = melt(CTscores, id.var="initials") ggplot(CTscores.m, aes(x=variable, y=value)) + geom_dotplot(binaxis="y", stackdir="up",binwidth=0.03) + theme_bw()+coord_flip() In order to distinguish the points, it would be convenient to just add color,

Matlab: Combine the legends of shaded error and solid line mean

荒凉一梦 提交于 2019-12-05 09:07:33
I am using this FEX entry to plot the horizontal shaded error bars for a variable plotted on the X-axis. This variable is plotted in different regions/zones and, therefore, there are 3 shaded error bars for 3 zones. I would like to combine the legends of the error bars (shaded region) as well as the mean (solid line) of any zone into a single legend represented by a solid line (or solid line inside a patch) of the same color as the zone. THE WAY MY CODE WORKS FOR PLOTTING: A synthetic example of the way I am plotting is shown below fh = figure(); axesh = axes('Parent', fh); nZones = 4; nPts =

reverse order in R leaflet continuous legend

故事扮演 提交于 2019-12-05 07:48:10
I am trying to reverse the value display of my leaflet legend in R. This post covers categorical data, but I am working with continuous data. Here's a toy example: map <- leaflet() %>% addProviderTiles('Esri.WorldTopoMap') x <- 1:100 pal <- colorNumeric(c("#d7191c","#fdae61","#ffffbf","#abd9e9", "#2c7bb6"), x) map %>% addLegend('topright', pal=pal, values=x) I'd like the legend to read 100 at the top and 1 on the bottom with the colors reversed. I can certainly reverse the colors in colorNumeric() , but reversing the order of the labels is harder. I have tried reversing the order of the values