legend

Chart.js legend took up too much spaces

十年热恋 提交于 2019-11-28 03:51:47
问题 I was having some problem with chart.js legend. The legend with long text took up too much spaces which resulting in the reduce in the size of my pie chart: Another example is this: If I got more legend, the doughnut chart will eventually becomes smaller and smaller. I tried to set maxWidth but to no avail. var options = { layout: { padding: { top: 5 } }, responsive: true, maintainAspectRatio: false, legend: { display: true, position: 'right', maxWidth: 100, onClick: null }, animation: {

How to create a draggable legend in matplotlib?

倖福魔咒の 提交于 2019-11-28 03:40:13
I'm drawing a legend on an axes object in matplotlib but the default positioning which claims to place it in a smart place doesn't seem to work. Ideally, I'd like to have the legend be draggable by the user. How can this be done? Adam Fraser Note: This is now built into matplotlib leg = plt.legend() if leg: leg.draggable() will work as expected Well, I found bits and pieces of the solution scattered among mailing lists. I've come up with a nice modular chunk of code that you can drop in and use... here it is: class DraggableLegend: def __init__(self, legend): self.legend = legend self

Single legend when using group, linetype and colour in ggplot2?

一世执手 提交于 2019-11-28 03:31:54
问题 I am creating a very simple plot that groups data and uses the grouping variable to determine linestyle and colour. I then override those using 'scale_linetype_manaul' and 'scale_colour_manual'. So far so good, but when I try to modify legend labels or its title, the legend splits into two parts: one for linetype and one for colour. I just want one legend, but with the custom labels and title. Following this question, I made sure to name both scale objects the same, but that doesn't appear to

Add abline to legend

 ̄綄美尐妖づ 提交于 2019-11-28 02:17:39
First, sorry for posting without reproducible data. Hope you guys understand my question. This is my code. At the end of the code, I am trying to add abline. With the code, I am trying to add the name of abline to the legend but it does not work. ggplot(aes(x = week_id2, y = Index, color = Chain2, linetype = Chain2, group = Chain2), data = data00 + geom_point(aes(shape=Chain2), size = 3) + geom_line() + scale_linetype_manual(values=c("twodash", "dashed", "dotted", "dotdash", "longdash")) + scale_shape_manual(values=c(1:5)) + xlab("Week") + ylab("Index") + geom_hline(aes(yintercept=1)) As shown

ggplot2: show missing value colour in legend

眉间皱痕 提交于 2019-11-28 02:02:10
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 legend. Thanks Workaround for the problem would be to replace NA values in your data with same other

Global legend using grid.arrange (gridExtra) and lattice based plots

家住魔仙堡 提交于 2019-11-28 01:49:34
问题 I am producing four plots using xyplot (lattice) and further combine them with grid.arrange (gridExtra). I would like to obtain a graph with a common global legend. The closest that I have reached is the following. They have to be in a matrix layout, otherwise an option would be to put them in a column and include only a legend for the top or bottom one. # Load packages require(lattice) require(gridExtra) # Generate some values x1<-rnorm(100,10,4) x2<-rnorm(100,10,4) x3<-rnorm(100,10,4) x4<

Fill the right column of a matplotlib legend first

风流意气都作罢 提交于 2019-11-28 01:46:18
问题 Hey I am trying to fit a legend onto a plot so that it doesn't obscure the graph. import numpy as np import matplotlib.pyplot as plt X = np.linspace(0,100,11) plt.plot(X,-X, label='plot 1') plt.plot(X,-2*X, label='plot 2') plt.plot(X,-3*X, label='plot 3') leg=plt.legend(ncol=2) leg.get_frame().set_visible(False) plt.show() So in the minimum working example, above, what I want to be able to do is move the 'plot 2' label in the legend into the right column, i.e. directly under 'plot 3'. Any

Matplotlib adding legend based on existing color series

╄→尐↘猪︶ㄣ 提交于 2019-11-28 01:28:40
问题 I plotted some data using scatter plot and specified it as such: plt.scatter(rna.data['x'], rna.data['y'], s=size, c=rna.data['colors'], edgecolors='none') and the rna.data object is a pandas dataframe that is organized such that each row represents a data point ('x' and 'y' represents the coordinate and 'colors' is an integer between 0-5 representing the color of the point). I grouped the data points into six distinct clusters numbered 0-5, and put the cluster number at each cluster's mean

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

試著忘記壹切 提交于 2019-11-28 01:09:47
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 = map, aes(long, lat, group = group, fill = value)) + scale_fill_gradient2(low = "brown3", mid =

Can ggplot2 control point size and line size (lineweight) separately in one legend?

旧时模样 提交于 2019-11-27 23:03:49
An example using ggplot2 to graph groups of data points and lines connecting the means for each group, mapped with the same aes for shape and for linetype : p <- ggplot(mtcars, aes(gear, mpg, shape = factor(cyl), linetype = factor(cyl))) + geom_point(size = 2) + stat_summary(fun.y = mean, geom = "line", size = 1) + scale_shape_manual(values = c(1, 4, 19)) Problem is that point symbols in the legend appear a bit too small to see, relative to the line symbols: Trying to enlarge point size in legend also enlarges lineweight, so that is not useful here. p1 <- p + guides(shape = guide_legend