legend

Combined line & bar geoms: How to generate proper legend?

∥☆過路亽.° 提交于 2019-11-30 07:30:48
The legend for d2 looks fine; for d1 , I would like to show just the hoizontal line against a white/transparent backgounnd. df = data.frame( Date = c("2012-11-30", "2012-12-03", "2012-12-04"), d1 = c(9, 5, 11), d2 = c(4, 6, 3) ) ggplot(df, aes(Date)) + geom_bar(aes(y = d2, color = "d2"), stat="identity", fill = "red") + geom_line(aes(y = d1, group = 1, color = "d1")) + scale_colour_manual("", values=c("d1" = "blue", "d2" = "red")) It is not an elegant solution but at least it gives some result. I added aes(fill="d2") in geom_bar() and removed fill="red" . Then I added separate scales for line

creating a matplotlib scatter legend size related

不想你离开。 提交于 2019-11-30 06:53:35
I am looking for a way to include a (matplotlib) legend that describe the size of points in a scatter plot, as this could be related to another variable, like in this basic example: import numpy as np import matplotlib.pyplot as plt N = 50 x = np.random.rand(N) y = np.random.rand(N) a2 = 400*np.random.rand(N) plt.scatter(x, y, s=a2, alpha=0.5) plt.show() (inspired from: http://matplotlib.org/examples/shapes_and_collections/scatter_demo.html ) so in the legend there would be ideally few spots corresponding to sizes 0-400 (the a2 variable), according to s descriptor in scatter . Ffisegydd The

R ggplot2: legend should be discrete and not continuous

时光毁灭记忆、已成空白 提交于 2019-11-30 06:50:49
问题 I have the following data: benchmark mispredpenal IPC pred ammp 1 1.0589 2lev ammp 5 1.0450 2lev ... and use the following command: ggplot(IPC, aes(x = benchmark, y = IPC, group=mispredpenal, colour=mispredpenal)) + geom_point() + geom_line() Everything looks like it should, but I would like the legend to be discrete, and not the continuous (gradient). How should I do this? Edit: Misprediction is either 1, 5, 9, 13 or 17. 回答1: You want the variable mispredpenal to be a factor in that case:

Adding a chart legend in D3

佐手、 提交于 2019-11-30 06:03:56
I am having trouble adding a chart legend to my d3js chart. Here is my current approach: var legend = svg.append("g") .attr("class", "legend") .attr("x", w - 65) .attr("y", 25) .attr("height", 100) .attr("width", 100); legend.append("rect") .attr("x", w - 65) .attr("y", 25) .attr("width", 10) .attr("height", 10) .style("fill", function(d) { return color_hash[dataset.indexOf(d)][1] }); legend.append("text") .attr("x", w - 65) .attr("y", 25) .text(function(d) { return color_hash[dataset.indexOf(d)][0] + ": " + d; }); Then I am attempting to style the .legend class: .legend { padding: 5px; font:

R Leaflet - use date or character legend labels with colorNumeric() palette

无人久伴 提交于 2019-11-30 05:49:31
问题 I have a dataset with lat/lon and a timestamp. I want the color of the markers to show time with a continous palette. I am using colorNumeric() with julian dates earlier created using julian(x, "2015-01-01") . data = structure(list(timestamp = structure(c(1434056453, 1434148216, 1434153635, 1434245436, 1434358840, 1434364288, 1434369611, 1434461435, 1434466830, 1434558725), class = c("POSIXct", "POSIXt"), tzone = ""), lon = c(-119.8777, -119.9614, -119.8769, -119.8775, -120.2283, -120.2285,

scatter plot with legend colored by group without multiple calls to plt.scatter

一个人想着一个人 提交于 2019-11-30 05:43:35
问题 pyplot.scatter allows for passing to c= an array that corresponds to groups, which will then color the points based on those groups. However, this seems to not support generating a legend without specifically plotting each group separately. So, for example, a scatter plot with groups colored can be generated by iterating over the groups and plotting each separately: import matplotlib.pyplot as plt from sklearn.datasets import load_iris feats = load_iris()['data'] target = load_iris()['target'

legend tag and Chrome

☆樱花仙子☆ 提交于 2019-11-30 05:29:59
I've looked everywhere but to no avail. I got a <legend> in a form, which displays as I want in every browsers, except in Chrome. It's like it sits outside of the fieldset, or it's like it goes on top of the next element. And it's very annoying. I can't even put margins on it. Why does it display like in that way? And is there a workaround? HTML: <fieldset class="col-12-box-bottom add-extras"> <legend class="plus">Add Promotion Code</legend> <ul id="promo-fields"> <li><input class="field-small" type="text" /></li> <li><button class="but-sec" type="submit">Apply</button></li> </ul> </fieldset>

Add annotation and segments to groups of legend elements

强颜欢笑 提交于 2019-11-30 05:20:09
My ggplot has the following legend: I want to group my individual legend variables, and add the group names and "brackets" like shown in legend below: My data has 2 columns: 1 - States of USA 2 - Activity level which has a range from 10 (High) - 1 (Low) I am also using data - us<-map_data("state"), which is included in ggplot/map package. My code: ggplot()+ geom_map(data=us, map=us,aes(x=long, y=lat, map_id=region), fill="#ffffff", color="#ffffff", size=0.15) + geom_map(data=dfm4,map=us,aes(fill=ACTIVITY.LEVEL,map_id=STATENAME) ,color="#ffffff", size=0.15)+ scale_fill_manual("Activity", values

MATLAB graph plotting: assigning legend labels during plot

删除回忆录丶 提交于 2019-11-30 05:11:15
I am plotting data in a typical MATLAB scatterplot format. Ordinarily when plotting multiple datasets, I would use the command 'hold on;', and then plot each of the data, followed by this to get my legend: legend('DataSet1', 'DataSet2') % etcetera However, the (multiple) datasets I am plotting on the same axes are not necessarily the same datasets each time. I am plotting up to six different sets of data on the same axes, and there could be any combination of these shown (depending on what the user chooses to display). Obviously that would be a lot of elseif's if I wanted to setup the legend

ggplot2: boxplot with colors and text labels mapped to combination of two categorical variables

家住魔仙堡 提交于 2019-11-30 05:08:52
问题 I would like to create a boxplot with ggplot2 from a dataset densityAGRLKA with 3 categorical variables (species, location, position) on the x-axis. The following function: ggplot(densityAGRLKA, aes(species, density, fill=location, alpha=position), dodge=species, position) + stat_boxplot(geom ='errorbar') + geom_boxplot() creates a plot, in which the grouping of the species is fine, but the colours are misleading. I have no idea how to fix this. I need a plot with the following properties: