legend

ggplot2: show missing value colour in legend

萝らか妹 提交于 2019-11-26 22:05:18
问题 Just wondering what is required so the colour for missing values is shown in the legend? Looking at example from the UseR! ggplot2 book, p94 p <- qplot(sleep_total, sleep_cycle, data=msleep, colour=vore) p + scale_colour_hue(na.value = "Black") p + scale_colour_hue("What does \nit eat?", na.value="Black", breaks=c("herbi", "carni", "omni", "insecti", NA), labels=c("plants", "meat", "both", "insects", "don't know")) the data point for vore=NA is shown in the plot but NA is not listed in the

Add a box for the NA values to the ggplot legend for a continous map

限于喜欢 提交于 2019-11-26 21:50:19
问题 I have got a map with a legend gradient and I would like to add a box for the NA values. My question is really similar to this one and this one. Also I have read this topic, but I can't find a "nice" solution somewhere or maybe there isn't any? Here is an reproducible example: library(ggplot2) map <- map_data("world") map$value <- setNames(sample(-50:50, length(unique(map$region)), TRUE), unique(map$region))[map$region] map[map$region == "Russia", "value"] <- NA ggplot() + geom_polygon(data =

using mpatches.Patch for a custom legend

▼魔方 西西 提交于 2019-11-26 21:02:12
问题 I'm using the following code to create a custom matplotlib legend. import matplotlib.patches as mpatches import matplotlib.pyplot as plt colors = ["g", "w"] texts = ["Green Data Description", "RedData Description"] patches = [ mpatches.Patch(color=colors[i], label="{:s}".format(texts[i]) ) for i in range(len(texts)) ] plt.legend(handles=patches, bbox_to_anchor=(0.5, 0.5), loc='center', ncol=2 ) The resulted legend is as follows: 1 - The white symbol in the legend is not shown because that the

How to change font family in a legend in an R-plot?

旧巷老猫 提交于 2019-11-26 20:39:46
问题 I have a graph use the base graphics package. For the labels on specific points I use text(i, MSSAcar$summary[i,7]+.7, qld$LGA[i], col='red', cex=.7, family='serif') I have also used this in the plot for main titles and axis labels. They all come out as expected. When I add a legend I cannot seem to be able to set the font family. Can anyone help please. Thanks. 回答1: Set the family plotting parameter before calling legend() to the value you want. Do this via an explicit call to par() . Here

Matplotlib savefig with a legend outside the plot

爱⌒轻易说出口 提交于 2019-11-26 20:32:16
问题 Reading the following article, I managed to put a legend outside plot. How to put the legend out of the plot code: import matplotlib.pyplot as pyplot x = [0, 1, 2, 3, 4] y = [xx*xx for xx in x] fig = pyplot.figure() ax = fig.add_subplot(111) box = ax.get_position() ax.set_position([box.x0, box.y0, box.width*0.8, box.height]) ax.plot(x, y) leg = ax.legend(['abc'], loc = 'center left', bbox_to_anchor = (1.0, 0.5)) #pyplot.show() fig.savefig('aaa.png', bbox_inches='tight') pyplot.show() displays

Place a legend for each facet_wrap grid in ggplot2

旧时模样 提交于 2019-11-26 20:08:46
I have this data frame: Date Server FileSystem PercentUsed 1 12/1/2011 A / 60 2 1/2/2012 A /var 50 3 2/1/2012 A tmp 90 4 2/10/2012 A /db 86 5 2/13/2012 A /app 90 6 12/1/2011 B C: 67 7 1/2/2012 B D: 67 8 2/1/2012 B F: 34 9 2/10/2012 B /restore 89 10 2/13/2012 B G: 56 11 12/1/2011 C / 90 12 1/2/2012 C /tmp 78 13 2/1/2012 C /data 67 14 2/10/2012 C /Storage 34 15 2/13/2012 C /database 12 dput(x) structure(list(Date = structure(c(2L, 1L, 3L, 4L, 5L, 2L, 1L, 3L, 4L, 5L, 2L, 1L, 3L, 4L, 5L), .Label = c("1/2/2012", "12/1/2011", "2/1/2012", "2/10/2012", "2/13/2012"), class = "factor"), Server =

How to show legend for only a specific subset of curves in the plotting?

时光怂恿深爱的人放手 提交于 2019-11-26 19:27:53
问题 t = 0 : 0.01 : 2 * pi; s = sin(t); c = cos(t); m = -sin(t); hold on; plot(t, s, 'r'); plot(t, c, 'b'); plot(t, m, 'g'); hold off; legend('', 'cosine', ''); There are several curves in my plotting. I want to display legend for only some of them. How do I do it? For example, how do I make only the legend for the cosine curve visible in the plotting above? When I call the legend() functions as legend('', 'cosine'); instead of adding the empty third parameter, indeed the third green line is

Leaflet Legend for Custom Markers in R

社会主义新天地 提交于 2019-11-26 18:22:35
问题 I have an R Shiny app that uses Leaflet to create an interactive map. On this map, a categorical variable is used to designate different kinds of points and is visualized using custom markers (different icons, depending on the factor level). What I would like to do is add a legend to the plot, but have the legend show the various marker icons instead of solid colours. The legends tutorial does not cover this. I have come across another SO answer that seems to solve this - but it was done in

Legend of a raster map with categorical data

十年热恋 提交于 2019-11-26 18:17:16
问题 I would like to plot a raster containing 4 different values (1) with a categorical text legend describing the categories such as 2 but with colour boxes: I've tried using legend such as : legend( 1,-20,legend = c("land","ocean/lake", "rivers","water bodies")) but I don't know how to associate one value to the displayed color. Is there a way to retrieve the colour displayed with 'plot' and to use it in the legend? 回答1: The rasterVis package includes a Raster method for levelplot() , which

ggplot separate legend and plot

我的未来我决定 提交于 2019-11-26 17:52:57
I am using the grid lpackage to place my graphs that I made with ggplot2 : library(ggplot2) library(grid) Layout <- grid.layout(nrow = 4, ncol = 4, widths = unit(1, "null"), heights = unit(c(0.4, 0.8, 1.2, 1.2), c("null", "null", "null"))) grid.show.layout(Layout) plot1 = ggplot(diamonds, aes(clarity, fill = color)) + geom_bar() + facet_wrap(~cut, nrow = 1) print(plot1 + theme(legend.position = "none"), vp = viewport(layout.pos.row = 3, layout.pos.col = 1:4)) The problem is that I want to put the plot on the third row (3,1) - (3,4) and put the legend at the (4,4) position. Unfortunately, I can