legend

Merge legends of separate geom layers

感情迁移 提交于 2019-12-02 10:17:45
I am plotting point data from two separate layers on a map and would like to display the information of both layers in one legend. Here's some code to illustrate the problem: set.seed(42) lat1 <- rnorm(10, 54, 12) long1 <- rnorm(10, 44, 12) val1 <- rnorm(10, 10, 3) lat2 <- rnorm(10, 54, 12) long2 <- rnorm(10, 44, 12) val2 <- rnorm(10, 10, 3) df1 <- as.data.frame(cbind(long1, lat1, val1)) df2 <- as.data.frame(cbind(long2, lat2, val2)) library(ggplot2) library(scales) f <- ggplot() + geom_point(data=df1, aes(x=lat1, y=long1, size=val1, fill=val1), shape=21, alpha=0.6) + scale_size_continuous

Adding a legend when using imagesc, including white for NaN

爷,独闯天下 提交于 2019-12-02 10:11:03
问题 I have a 35x43 matrix of data with vales ranging from 1-6 and lots of NaNs. I want to NaNs to be white, and the numbers to each be a different colour. I need a legend with the 6 different colour and labels on it. I can achieve most of this with the following code, however the colours in the legend do not match the colours in the figure. See code below figure(6) subplot(1,2,1) imagesc(lut) title('Highest Weighted Predictor variable for each Pixel') ylabel('Longitude') xlabel('Latitude') caxis(

Custom legend based on color of bars in a dc.js composite chart

别来无恙 提交于 2019-12-02 09:36:16
问题 I implemented a composite chart with two bar charts in which one bar chart consists of bars with different colored bars. Now, I want to create a custom legend that represents each color bar (similar to https://dc-js.github.io/dc.js/examples/pie-external-labels.html used for pie chart). Below is the code snippet of what I've done so far: var buttonPress = dc.barChart(composite) .dimension(joyTimeDimension) //.renderlet(colorRenderlet) //.colors('red') .colors(colorbrewer.Set1[5]) .colorDomain(

how to show legend items of patches in bokeh

非 Y 不嫁゛ 提交于 2019-12-02 08:12:51
In the following set up, I create a area chart based on the basic example. How do I get the legend for my input automatically or even programatically. For now I get only legend with one item 'a' and the first color. from bokeh.plotting import * ... patches([x2 for a in areas], list(areas.values()), color=colors, alpha=0.8, line_color=None, legend='a', title="hello chart") legend().orientation = "top_right" # what other options, may here? show() What is the format to pass into patches for the legend as value or how can I trigger the legend() to show an item and color for every item in the plot?

Remove legend key in matplotlib

拥有回忆 提交于 2019-12-02 06:51:16
I want to show a legend text but without a key (the rectangular box or line that appears by default). plt.hist(x, label = 'something') I don't want the box next to the legend "something". How to remove it? First of all, you may decide not to create a legend at all and instead put some label in to corner of the plot. import matplotlib.pyplot as plt import numpy as np x = np.random.normal(size=160) plt.hist(x) plt.text(0.95,0.95, 'something', ha="right", va="top", transform=plt.gca().transAxes) plt.show() If you already created the legend and want to remove it, you can do so by plt.gca().get

Legend in ggplot2, remove level

早过忘川 提交于 2019-12-02 05:24:43
问题 My data: df <- data.frame(sp = c(LETTERS[1:8]), tr = c("NS", "LS", "NS", "LS", "LS", "HS", "HS", "HS"), bv = c(14, 5, 11, 5.6, 21, 5.4, 2, 4.8), av = c(0.0, 14, 21, 48.4, 15, 55.6, 37, 66.2)) I do the bar plot library(reshape2) df1 <- melt(df, id.vars = c("sp", "tr")) ggplot(aes(sp, value, fill = variable) , data = df1) + theme_classic() + geom_bar(aes(lty = tr), lwd = 1.2, data = df1, stat = "identity", colour = "black", width =.8) + theme(legend.position = "bottom" ) + scale_linetype

Custom legend based on color of bars in a dc.js composite chart

那年仲夏 提交于 2019-12-02 04:24:27
I implemented a composite chart with two bar charts in which one bar chart consists of bars with different colored bars. Now, I want to create a custom legend that represents each color bar (similar to https://dc-js.github.io/dc.js/examples/pie-external-labels.html used for pie chart). Below is the code snippet of what I've done so far: var buttonPress = dc.barChart(composite) .dimension(joyTimeDimension) //.renderlet(colorRenderlet) //.colors('red') .colors(colorbrewer.Set1[5]) .colorDomain([101, 105]) .colorAccessor(function (d) { return d.value; }) .group(btnGroup, "Button Press")

Add a legend to a ggplot2 scatter plot including additional lines

旧城冷巷雨未停 提交于 2019-12-02 04:11:34
I would like to add a legend to a ggplot2 scatter graph which distinguishes between a regression line and a separate line I've added. For example, library(ggplot2) set.seed(123) data1=rnorm(1000,1,2) data2=rnorm(1000,1,4) DF=data.frame(data1,data2) ggplot(DF,aes(data1,data2))+geom_point(colour="dodgerblue",alpha=0.75)+geom_smooth(method=lm,se=F,aes(colour="Line of best fit"))+ geom_abline(intercept = 0, slope = 1, linetype="dashed", colour="black", alpha=1,size=1) There are two lines on this plot, a red regression line, and a black line with equation y=x . I have managed to add a regression

Sort legend order in ggmap

橙三吉。 提交于 2019-12-02 03:14:35
问题 How can I sort the legend order in a ggmap? I have the following code: mymap <- ggmap(map) + geom_point(data = mypoints, aes(x =lon, y= lat,colour = month), alpha=0.5, size=5) I would like the months to appear in order (i.e. Jan, Feb, Mar, Apr... etc.) 回答1: Edit As stated by Tyler Rinker, one way is to use the function factor to order factor levels (in this case, months ). I created some data to use with ggplot, but you can adapt to your data and use the logic with ggmap. library(ggplot) x =

Adding a legend when using imagesc, including white for NaN

给你一囗甜甜゛ 提交于 2019-12-02 03:00:16
I have a 35x43 matrix of data with vales ranging from 1-6 and lots of NaNs. I want to NaNs to be white, and the numbers to each be a different colour. I need a legend with the 6 different colour and labels on it. I can achieve most of this with the following code, however the colours in the legend do not match the colours in the figure. See code below figure(6) subplot(1,2,1) imagesc(lut) title('Highest Weighted Predictor variable for each Pixel') ylabel('Longitude') xlabel('Latitude') caxis([0, 7]) myColorMap = jet(7); myColorMap(1,:) = 1; colormap(myColorMap); M = jet(7); % Notice the 3,