bar-chart

Text in barplot in R

回眸只為那壹抹淺笑 提交于 2021-02-08 20:01:26
问题 I have a problem when adding values in a barplot in R. The problem is that I cannot place the values in the middle of each bar balance<- c(-4.3963714,0.2335795,-0.2777250,-2.0037130,-1.2526801, -6.4556516) barnames<-c("E1","E11","E12","E5","E7","E9") barplot(balance,ylim=c(-8,2),col=c(if ((balance[1])>0) "blue" else "red",(if ((balance[2])>0) "blue" else "red"),(if ((balance[3])>0) "blue" else "red"), (if ((balance[4])>0) "blue" else "red"),(if ((balance[5])>0) "blue" else "red"), (if (

Text in barplot in R

生来就可爱ヽ(ⅴ<●) 提交于 2021-02-08 20:01:16
问题 I have a problem when adding values in a barplot in R. The problem is that I cannot place the values in the middle of each bar balance<- c(-4.3963714,0.2335795,-0.2777250,-2.0037130,-1.2526801, -6.4556516) barnames<-c("E1","E11","E12","E5","E7","E9") barplot(balance,ylim=c(-8,2),col=c(if ((balance[1])>0) "blue" else "red",(if ((balance[2])>0) "blue" else "red"),(if ((balance[3])>0) "blue" else "red"), (if ((balance[4])>0) "blue" else "red"),(if ((balance[5])>0) "blue" else "red"), (if (

Overlapping Bar Chart using Chart.js

放肆的年华 提交于 2021-02-08 13:41:48
问题 I want to develop a bar chart as shown below is it possible to develop it using chart.js? 回答1: Yes this is possible, see examples in this thread on Github https://github.com/chartjs/Chart.js/issues/5224. Notice the comment relating to offset, which will apply to versions of Chart js > 2.4. 来源: https://stackoverflow.com/questions/43271197/overlapping-bar-chart-using-chart-js

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.

stacked barplot with aggregated data (ggplot2)

隐身守侯 提交于 2021-02-08 08:21:30
问题 I have some major problems with ggplot2. Even though it might be a very easy question to you I couldnt manage yet to get it right (I have read a ggplot2-book and was looking on stackoverflow as well). Orginally there was a dataset consisting of a factor variable (country) and a dichotomous variable. Unfortunately I dont have my data in this extended format myself: I have two variables "var1" and "var2". var1 gives the number of cases in the original dataset where a certain condition is true

How to correctly order segments by value, within an individual bar, on a bar chart in ggplot (even when changing from a factor)

北城以北 提交于 2021-02-08 07:39:38
问题 I am trying in vain to get the segments within each bar of the bar chart to order based on the value (largest value within a bar on the bottom, smallest on top). I've researched this and would think this should work, but something is not right and I can't find the issue. I tried this solution here, but no luck. Here is a reproducible example: library(dplyr) my_repro <- structure(list(Date = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = "2020-04-01", class =

Fine control of bar width in barplot

て烟熏妆下的殇ゞ 提交于 2021-02-08 02:35:14
问题 I want to combine 4 figures in the same plot. Each barplot is related to the image plot. I want the bar width to be exactly the same width as the grid width in the image plot. The up-barplot and the left-barplot. I have pasted my code to follow. How can I modify for this purpose? Or can I use ggplot2 for this? datMat <- matrix(rep(1, 100), nrow=10) op=par(oma=c(1, 1, 1, 1), mar=c(1, 1, 1, 1), lwd=0.2, cex=.5) nf <- layout(matrix(c(0, 1, 0, 2, 3, 4), 2, 3, byrow=TRUE), widths=c(1, 6, 1),

Grouped and stacked barplot using base R

随声附和 提交于 2021-02-07 13:00:26
问题 I would like to create a combination bar plot where within data1 and data2 are stacked while between data1 and data2 are grouped in base R graphics. Something like this in arrangement: data1 <- matrix(c(1:5, rep(1,5), rep(4,5)), ncol=5) data2 <- matrix(c(2:6, rep(2,5), rep(3,5)), ncol=5) # stacked bar barplot(data1) #grouped var barplot(data1, beside=TRUE) Any idea how can I do this? I know we can do this using different plots or facets but I would like to present them side by side in a

Barplot with ggplot 2 of two categorical variable facet_wrap according a third variable displayng percentage

∥☆過路亽.° 提交于 2021-02-07 10:16:14
问题 I would like to barplot in ggplot2 a categorical variable grouped according a second categorical variable and use facet_wrap to divide them in different plots. Than I would show percentage of each. Here a reproducible example test <- data.frame( test1 = sample(letters[1:2], 100, replace = TRUE), test2 = sample(letters[3:5], 100, replace = TRUE), test3 = sample(letters[9:11],100, replace = TRUE ) ) ggplot(test, aes(x=factor(test1))) + geom_bar(aes(fill=factor(test2), y=..prop.., group=factor

Barplot with ggplot 2 of two categorical variable facet_wrap according a third variable displayng percentage

醉酒当歌 提交于 2021-02-07 10:14:17
问题 I would like to barplot in ggplot2 a categorical variable grouped according a second categorical variable and use facet_wrap to divide them in different plots. Than I would show percentage of each. Here a reproducible example test <- data.frame( test1 = sample(letters[1:2], 100, replace = TRUE), test2 = sample(letters[3:5], 100, replace = TRUE), test3 = sample(letters[9:11],100, replace = TRUE ) ) ggplot(test, aes(x=factor(test1))) + geom_bar(aes(fill=factor(test2), y=..prop.., group=factor