legend

Legend ordering in ggplot2

旧城冷巷雨未停 提交于 2019-12-04 17:32:06
I created the following graph in R using ggplot2 . As you can see, the order in the legend is not exactly what it should be: I would like to have "4 years" coming after "1 year". I was wondering how this can be achieved. Source code: require("ggplot2") require("scales") # I have 5 data files containing two columns (x and y values) d1 = read.table("1yr.txt")$V2 d2 = read.table("4yr.txt")$V2 d3 = read.table("15yr.txt")$V2 d4 = read.table("25yr.txt")$V2 d5 = read.table("40yr.txt")$V2 rank1 = read.table("1yr.txt")$V1 rank2 = read.table("4yr.txt")$V1 rank3 = read.table("15yr.txt")$V1 rank4 = read

Writing variables as subscripts in math mode

余生长醉 提交于 2019-12-04 16:31:08
I am trying to plot some data, using a for loop to plot distributions. Now I want to label those distributions according to the loop counter as the subscript in math notation. This is where I am with this at the moment. import matplotlib.pyplot as plt import numpy as np import matplotlib.mlab as mlab mean = [10,12,16,22,25] variance = [3,6,8,10,12] x = np.linspace(0,40,1000) for i in range(4): sigma = np.sqrt(variance[i]) y = mlab.normpdf(x,mean[i],sigma) plt.plot(x,y,label=$v_i$) # where i is the variable i want to use to label. I should also be able to use elements from an array, say array[i

How to reverse legend (labels and color) so high value starts downstairs?

[亡魂溺海] 提交于 2019-12-04 15:59:09
问题 whats the best way to invert the legend label order so the 7 is down and the 1 is upstairs? df$day <- as.numeric(df3$day) blues <- colorRampPalette(c('#132B43', '#56B1F7')) p4 <- ggplot(subset(df,feedback==1&stp>20), aes(x=correct, fill=day, colour=day)) + geom_histogram(colour="black", binwidth=10) + facet_grid(day ~ .) + ggtitle("Over-pronation histogram") + ylab("Count (150s period)") + xlab("% Steps in over-pronation") +guide_legend(reverse = false) 回答1: Your code is quite strange, with

seaborn: legend with background color

不想你离开。 提交于 2019-12-04 15:44:52
问题 The following question explains how to change the background color of a legend: matplotlib legend background color. However, if I use seaborn this does not work. Is there a way to do this? import matplotlib.pyplot as plt import numpy as np a = np.random.rand(10,1) plt.plot(a, label='label') legend = plt.legend() frame = legend.get_frame() frame.set_facecolor('green') plt.show() import seaborn as sns plt.plot(a, label='label') legend = plt.legend() frame = legend.get_frame() frame.set

ggplot and two different geom_line(): the legend does not appear

爱⌒轻易说出口 提交于 2019-12-04 15:22:18
I have the following code ( dput data for the data sets is here): ruz <- structure(list(date = structure(c(16617, 16618, 16619, 16622, 16623, 16624, 16625, 16626, 16629, 16630, 16631, 16632, 16633, 16636, 16637, 16638, 16639, 16640, 16643, 16644, 16645, 16646, 16647, 16650, 16651, 16652, 16653, 16654, 16657, 16658, 16659, 16660, 16661, 16664, 16665, 16666, 16667, 16668, 16671, 16672, 16673, 16674, 16675, 16678, 16679, 16680, 16681, 16682, 16685, 16686, 16687, 16688, 16689, 16692, 16693, 16694, 16695, 16696, 16699, 16700, 16701, 16702, 16703, 16706, 16707, 16708, 16709, 16710, 16713, 16714,

matplotlib scatter plot with color label and legend specified by c option [duplicate]

送分小仙女□ 提交于 2019-12-04 15:00:48
This question already has an answer here: Matplotlib scatter plot with legend 5 answers I'd like to make this kind of scatter plot where the points have colors specified by the "c" option and the legend shows the color's meanings. The data source of mine is like following: scatter_x = [1,2,3,4,5] scatter_y = [5,4,3,2,1] group = [1,3,2,1,3] # each (x,y) belongs to the group 1, 2, or 3. I tried this: plt.scatter(scatter_x, scatter_y, c=group, label=group) plt.legend() Unfortunately, I did not get the legend as expected. How to show the legend properly? I expected there are five rows and each row

Keep ordering of my data in ggplot legend where color and shape are combined

只愿长相守 提交于 2019-12-04 14:32:58
I am creating a plot where I need to mix names, colors and shapes in a single legend. It seems the legend order my data alphabetically by className generating a mismatch with my class shapes and colors... I need to have unique shape per superclasses A, B, C so I expected to have A1, A2, A3 as triangles, and B1, B2 as circles. How can I force the legend names to follows the same order as colors and shapes as in my data? (I don't want alphabetical order in the legend which makes no sense for my real application) Here my data and code: library(ggplot2) x<-c(1,2,3,4,5,6,7,8,9) y<-c(1,1,2,2,2,3,3,3

How to wrap legend text in Chartjs?

回眸只為那壹抹淺笑 提交于 2019-12-04 12:56:16
My ChartJs legend text is overflowing in the same line when the text is too long. Is there any parameter that I can use to enable text-wrap. legend : { display : true, position : 'bottom', fullWidth: false, labels : { fontColor : "#000", // boxWidth : "3" } } In other chart libraries like highcharts, you just have to set width and the text will be wrapped if it exceeds the width. Is there such an option in ChartJS? Highcharts Library Example: legend: { itemStyle: { width: 90 // or whatever, auto-wrap }, } I tried using legendCallback, but in that case I will loose the 'onclick' useful

How to position the legend inside a fieldset with a border? [duplicate]

半腔热情 提交于 2019-12-04 08:53:00
问题 This question already has answers here : Prevent the fieldset element's border from going through the legend element (2 answers) Closed 4 years ago . According to the several references on the web, it is not possible to position a legend. So it is suggested to wrap it with span: <legend><span>Foo</span></legend> Then we can position the span inside the fieldset. but then when I want to add a border on top of the fieldset, there is a gap for the legend. Luckily, I've found that adding border

Legend in a bar plot in Matlab

删除回忆录丶 提交于 2019-12-04 08:46:09
问题 How can I plot a legend in a bar plot in Matlab? Here is the code: Y = [1.5056 0.72983 3.4530 3.2900 1.4839 12.9 ]; n = length(Y); h = bar(Y); colormap(summer(n)); grid on l = cell(1,6); l{1}='L'; l{2}='B'; l{3}='R'; l{4}='P'; l{5}='h'; l{6}='Ri'; legend(h,l); This give an error: Warning: Ignoring extra legend entries. I tried solutions which I found on the SO and web, but I couldn't resolve this. 回答1: Instead of legend, you can solve it using the tick labels for example: set(gca,'xticklabel'