Different legend-keys inside same legend in ggplot2

You can use override.aes= inside guides() function to change default appearance of legend. In this case your guide is color= and then you should set shape=c(NA,16) to remove shape for line and then linetype=c(1,0) to remove line from point. ggplot(df) + geom_line(aes(id, line, colour = “line”)) + geom_point(aes(id, points, colour = “points”))+ guides(color=guide_legend(override.aes=list(shape=c(NA,16),linetype=c(1,0))))

How to add a string as the artist in matplotlib legend?

I don’t think there’s a legend handler for text (see the list of available ones here). But you can implement your own custom legend handler. Here I’ll just modify the example at the above link: import matplotlib.pyplot as plt import matplotlib.text as mpl_text class AnyObject(object): def __init__(self, text, color): self.my_text = text self.my_color = color … Read more

How to move or position a legend in ggplot2

In versions > 0.9.3 (when opts was deprecated) theme(legend.position = “bottom”) Older version: Unfortunately it’s a bug in ggplot2 which I really really hope to fix this summer. Update: The bug involving opts(legend.position = “left”) has been fixed using the most current version of ggplot2. In addition, version 0.9.0 saw the introduction of guide_legend and … Read more

Two geom_points add a legend

If you rename your columns of the original data frame and then melt it into long format withreshape2::melt, it’s much easier to handle in ggplot2. By specifying the color and shape aesthetics in the ggplot command, and specifying the scales for the colors and shapes manually, the legend will appear. source(“http://www.openintro.org/stat/data/arbuthnot.R”) library(ggplot2) library(reshape2) names(arbuthnot) <- … Read more

How to add data table with legend keys to a MS Chart in C#?

Yes you can do that: Here are the steps I took: First we disable the original Legend as it can’t be manipulated the way we need to..: chart1.Legends[0].Enabled = false; Now we create a new one and a shortcut reference to it: chart1.Legends.Add(new Legend(“customLegend”)); Legend L = chart1.Legends[1]; Next we do some positioning: L.DockedToChartArea = … Read more