bar-chart

Combined line & bar geoms: How to generate proper legend?

心已入冬 提交于 2019-12-30 02:21:06
问题 The legend for d2 looks fine; for d1 , I would like to show just the hoizontal line against a white/transparent backgounnd. df = data.frame( Date = c("2012-11-30", "2012-12-03", "2012-12-04"), d1 = c(9, 5, 11), d2 = c(4, 6, 3) ) ggplot(df, aes(Date)) + geom_bar(aes(y = d2, color = "d2"), stat="identity", fill = "red") + geom_line(aes(y = d1, group = 1, color = "d1")) + scale_colour_manual("", values=c("d1" = "blue", "d2" = "red")) 回答1: It is not an elegant solution but at least it gives some

position legend of a stacked bar plot

ε祈祈猫儿з 提交于 2019-12-30 01:43:06
问题 I am trying to create a stacked bar plot, but I cannot position the legend so that it does not overlap any of the bars. I have tried adjusting the margins, setting xlim , using a separate legend statement and searching here, all without success. Indeed, the code for the example data set came from StackOverflow. I am using base R and prefer a base R solution. Thank you for any advice. setwd('c:/users/mmiller21/simple R programs/') jpeg(filename = "barplot.jpeg") set.seed(1234) x <- replicate(8

Is it possible to have different legend background colors for different data rows in Google bar chart, without breaking the chart?

故事扮演 提交于 2019-12-29 09:19:10
问题 See the example code: var data = new google.visualization.DataTable(); data.addColumn('string', 'Mac'); data.addColumn('number', 'Score'); data.addColumn({ type: 'string', role: 'style' }); data.addRows([ ['Mac model 12', 200, 'color: #8bba30; opacity: 0.75;'], ['Another Mac Model', 110, 'color: #ffcc33; opacity: 0.75;'], ]); var options = { title: '', width: 500, height: data.getNumberOfRows() * 40 + 100, hAxis: { minValue: 0, maxValue: 255, ticks: [0, 75, 150, 255], textPosition: 'out',

How to automate positioning of inner labels within a stacked barplot?

泪湿孤枕 提交于 2019-12-29 08:54:06
问题 I frequently have to produce stacked bar plots with labels. The way I've been coding the labels is very time intensive and I wondered if there was a way to code things more efficiently. I would like the labels to be centered on each section of the bars. I'd prefer base R solutions. stemdata <- structure(list( #had to round some nums below for 100% bar A = c(7, 17, 76), B = c(14, 10, 76), C = c( 14, 17, 69), D = c( 4, 10, 86), E = c( 7, 17, 76), F = c(4, 10, 86)), .Names = c("Food, travel,

How to automate positioning of inner labels within a stacked barplot?

时光总嘲笑我的痴心妄想 提交于 2019-12-29 08:54:06
问题 I frequently have to produce stacked bar plots with labels. The way I've been coding the labels is very time intensive and I wondered if there was a way to code things more efficiently. I would like the labels to be centered on each section of the bars. I'd prefer base R solutions. stemdata <- structure(list( #had to round some nums below for 100% bar A = c(7, 17, 76), B = c(14, 10, 76), C = c( 14, 17, 69), D = c( 4, 10, 86), E = c( 7, 17, 76), F = c(4, 10, 86)), .Names = c("Food, travel,

ggplot2: side by side barplot with one bar stacked and the other not

一曲冷凌霜 提交于 2019-12-29 08:12:27
问题 I am trying to create a barplot where for each category, two bars are plotted (side by side): one is for the "total", the other is stacked by subgroups. For example, in the following data frame, 'names' will be shown on x-axis. For each category in 'names', one bar will represent the value of 'total', the other will be a stacked bar representing values from 'aaa', 'bbb' and 'ccc'. I managed to get a 'back-to-back' plot but I don't know how to apply the 'dodge' position to this case to make

ggplot2: barplot with colors as a function of y-axis value

删除回忆录丶 提交于 2019-12-29 07:38:11
问题 I have this simple code (data + barplot) : dat <- c('Jan','Feb','Mar', 'Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec') val <- c(-2.5, 3, 2.5, -3.3, -1, 0.2, 6, 4.3, 5.5, 2, -1.9, -2.3) df <- data.frame(dat, val) bar <- ggplot(data = df, aes(x = factor(dat, levels = month.abb), y = val)) + geom_bar(stat = 'identity') print(bar) Elsewhere I created a heatmap using the following palette: # Palette LtoM <-colorRampPalette(c('red', 'yellow' )) Mid <- "snow3" MtoH <-colorRampPalette(c(

Clustered bar plot in gnuplot

ぐ巨炮叔叔 提交于 2019-12-29 04:34:19
问题 I have a simple result table which I want to plot as a clustered histogram plot in gnuplot. The data set has the category of content type of a webpage and the corresponding percentage share in two columns. I have this for two browsers. For example, For IE, Content Share Video 30% Audio 10% Flash 25% HTML 20% Javascript 15% For Chrome, Content Share Video 20% Audio 5% Flash 35% HTML 30% Javascript 10% Now I want to plot these two data together with the Content Type in the x-axis and the

plotting barplots with standard errors using R

ぐ巨炮叔叔 提交于 2019-12-29 01:58:30
问题 I am trying to plot a simple barplot with standard errors and its driving me crazy. I did look up some examples and got as far as this: rt5 <- data.frame(rtgrp=c(37.2,38.0,38.3,38.5,38.9), mort=c(35,11,16,8,4), se=c(0.08,0.01,0.005,0.01,0.02)) rt5 xvals=with(rt5, barplot(mort,names.arg=rtgrp, xlab="PTEMP_R group mean",ylab="%",ylim=c(0,max(mort+10+se)))) I am trying to get through the last line of script but have been on it for quite a while: with(rt5, arrows(xvals,mort,xvals,mort+se,length

How to plot a very simple bar chart (Python, Matplotlib) using input *.txt file?

穿精又带淫゛_ 提交于 2019-12-28 11:51:49
问题 I use Python 2.7 and matplotlib. I have a *.txt data file : 0 14-11-2003 1 15-03-1999 12 04-12-2012 33 09-05-2007 44 16-08-1998 55 25-07-2001 76 31-12-2011 87 25-06-1993 118 16-02-1995 119 10-02-1981 145 03-05-2014 first column of my file (numbers) should be on axis Y in my bar chart, and the second column from my file (dates) should be on axis OX in my histogram. I only know how to read the file: OX = [] OY = [] try : with open('data.txt', 'r') as openedFile : for line in openedFile : tab =