legend

How can I change the legend geometry in ggplot2

霸气de小男生 提交于 2021-02-11 11:50:36
问题 Hello say I plot this boxplot: library(ggplot2) DT <- data.frame( y = runif(400, max = 2), grp = sample(c('M', 'F'),size = 400, replace = T), x = rep(as.Date(1:10,origin='2011-01-01'), each = 40) ) p <- ggplot(DT) + geom_boxplot() + aes(x = x, y = y, group=interaction(x,grp), fill=grp) p Question is how can I replace those little boxes in the legend by lines (like I would have using graphics ) 回答1: easiest option might be to make the lines invisible, p + guides(fill = guide_legend(override

ggplot legend: change order of the automatic legend

大憨熊 提交于 2021-02-10 08:40:17
问题 I am struggling with the legend order in ggplot when there are several group of plots. Here is an example: library(ggplot2) library(data.table) data <- data.table(time = rep(1:50,4),dampingtime = rep(c(4,8,12,16),each = 50), excitation = rep(c(rep(0,10),rep(1,10),rep(0,30)),4)) data[,signal := time + .GRP, by = dampingtime] data[,dampingtime := as.factor(dampingtime)] Here I have > levels(data$dampingtime) [1] "4" "8" "12" "16" which I did accordingly to ggplot legends - change labels, order

ggplot legend: change order of the automatic legend

独自空忆成欢 提交于 2021-02-10 08:40:08
问题 I am struggling with the legend order in ggplot when there are several group of plots. Here is an example: library(ggplot2) library(data.table) data <- data.table(time = rep(1:50,4),dampingtime = rep(c(4,8,12,16),each = 50), excitation = rep(c(rep(0,10),rep(1,10),rep(0,30)),4)) data[,signal := time + .GRP, by = dampingtime] data[,dampingtime := as.factor(dampingtime)] Here I have > levels(data$dampingtime) [1] "4" "8" "12" "16" which I did accordingly to ggplot legends - change labels, order

Combining linetype and color in ggplot2 legend

本小妞迷上赌 提交于 2021-02-08 17:24:55
问题 I have a dataframe like this : > head(df_graph) treatment year mean se 1: AC 2005 0.3626147 0.03005057 2: AC 2006 0.3925465 0.02370335 3: AC 2007 0.3217444 0.02279881 4: AC 2008 0.3895656 0.05985077 5: AC 2009 0.3820191 0.01481586 6: AC 2010 0.3732695 0.03544626 ... And a (long) ggplot script : df_graph %>% # way to make 2 lines becoming 4 in a smooth way filter(treatment %in% c("Ambient", "Elevated")) %>% mutate(treatment = ifelse(treatment == "Ambient", "AA", "EE")) %>% bind_rows(df_graph)

Plotting bar charts with a colormap legend

可紊 提交于 2021-02-08 11:42:44
问题 Consider the following: import matplotlib.pyplot as plt from matplotlib import cm import numpy as np y = np.array([1, 4, 3, 2, 7, 11]) colors = cm.hsv(y / float(max(y))) plot = plt.scatter(y, y, c = y, cmap = 'hsv') plt.clf() plt.colorbar(plot) plt.bar(range(len(y)), y, color = colors) plt.show() I want to colormap legend to appear on the top right of the graph (much smaller of course). My image at the moment looks rather clunky as the colormap is clashing somewhat with the actual bars.

Display all levels in plotly subplot legend without duplicates

前提是你 提交于 2021-02-08 11:20:08
问题 I am trying to build a visualization with plotly combining multiple plots using subplot . I'd like to have a legend that shows all levels from the various plots passed to subplot without duplicates. Here is a simplified example of the problem: library(plotly) d <- data.frame( x1 = c('a', 'a', 'b', 'b'), x2 = c('a', 'b', 'b', 'c'), y = 3 + runif(4) ) p1 <- plot_ly(d[d$x1=='a', ], x=~x2, y=~y, color=~x2, type='bar', legendgroup=~x2) p2 <- plot_ly(d[d$x1=='b', ], x=~x2, y=~y, color=~x2, type=

Display all levels in plotly subplot legend without duplicates

 ̄綄美尐妖づ 提交于 2021-02-08 11:15:24
问题 I am trying to build a visualization with plotly combining multiple plots using subplot . I'd like to have a legend that shows all levels from the various plots passed to subplot without duplicates. Here is a simplified example of the problem: library(plotly) d <- data.frame( x1 = c('a', 'a', 'b', 'b'), x2 = c('a', 'b', 'b', 'c'), y = 3 + runif(4) ) p1 <- plot_ly(d[d$x1=='a', ], x=~x2, y=~y, color=~x2, type='bar', legendgroup=~x2) p2 <- plot_ly(d[d$x1=='b', ], x=~x2, y=~y, color=~x2, type=

How to add another legend to circular heat map in R

99封情书 提交于 2021-02-08 07:50:01
问题 I want to add another legend that tells me what ring of a circular heat map represents (from outer ring to inner ring). I tried the following from another answer previously: library(reshape) library(ggplot2) library(plyr) nba <- read.csv("http://datasets.flowingdata.com/ppg2008.csv") nba$Name <- with(nba, reorder(Name, PTS)) nba.m <- melt(nba) nba.m <- ddply(nba.m, .(variable), transform, value = scale(value)) # Convert the factor levels (variables) to numeric + quanity to determine size of

How to add another legend to circular heat map in R

大憨熊 提交于 2021-02-08 07:49:53
问题 I want to add another legend that tells me what ring of a circular heat map represents (from outer ring to inner ring). I tried the following from another answer previously: library(reshape) library(ggplot2) library(plyr) nba <- read.csv("http://datasets.flowingdata.com/ppg2008.csv") nba$Name <- with(nba, reorder(Name, PTS)) nba.m <- melt(nba) nba.m <- ddply(nba.m, .(variable), transform, value = scale(value)) # Convert the factor levels (variables) to numeric + quanity to determine size of

Showing different size circles in heatmap with legend using Matplotlib

我的梦境 提交于 2021-02-08 06:39:39
问题 I am asking a question stemming from this original post Heatmap with circles indicating size of population I am trying to replicate this using my dataframe, however, my circles are non aligning to the plot. Secondary, I want to also create a legend which indicates the value relative to the size of circle. x= {'ID': {0: 'GO:0002474', 1: 'GO:0052548', 2: 'GO:0002483', 3: 'GO:0043062', 4: 'GO:0060333'}, 'TERM': {0: 'antigen processing and presentation of peptide antigen via MHC class I', 1: