search for: geom_histogram

Displaying 20 results from an estimated 48 matches for "geom_histogram".

2010 May 10
1
ggplot: Trouble with xlim() and discrete scales
...and am a little confused. Sometimes discrete scales work like I'd expect, and sometimes they don't. For example... This works exactly like one would expect: df<-data.frame(names=c("Bob","Mary","Joe","Bob","Bob")) ggplot(df,aes(names))+geom_histogram() But this yields an error: ggplot(df,aes(names))+geom_histogram()+xlim("Bob") Error in data.frame(count = as.numeric(tapply(weight, bins, sum, na.rm = TRUE))$ arguments imply differing number of rows: 0, 1 ...as does this: ggplot(df,aes(names))+geom_histogram()+xlim("Bob"...
2009 Jul 21
1
geom_histogram help
Hi, I have a histogram.But I need seperate colours for fixed range of values.for eg. between 2-3 on the x axis a colour.3-4 another colour etc. and the legend has to say what each colour is.How can this be done in geom_histogram? -- Rajesh.J [[alternative HTML version deleted]]
2011 Mar 29
1
ggplot2: scale_y_log10() with geom_histogram
Dear ggplot2 users, is there an easy/elegant way to suppress zero count bars in histograms with logarithmic y axis ? One (made up) example would be qplot(exp(rnorm(1000))) + geom_histogram(colour = "cornsilk", fill = "darkblue") + scale_x_sqrt() + scale_y_log10() Thanks! Markus [[alternative HTML version deleted]]
2008 Jun 13
1
overlaid transparent histograms
...code not produce transparent bars? 1b) How can I manually specify the elements of the legend for this version of the plot? --8<---------------cut here---------------start------------->8--- ## Non-working version data(lexdec, package="languageR") g <- ggplot(lexdec) g + geom_histogram(aes(x=log(BNCw), fill = alpha("red", .5))) + geom_histogram(aes(x=log(BNCc), fill = alpha("blue", .5))) --8<---------------cut here---------------end--------------->8--- 2) Does anyone have a way to accomplish the same thing in lattice? I saw the post at http://w...
2011 Jun 07
1
ggplot2 Histogram with density curve
I am learning ggplot2 commands and I have figured out how to create histograms and density curves but I am not sure how to add a density curve on top of a histogram. Here are the two graphs that I created. ## Histogram t<-rnorm(500) w<-qplot(t, main="Normal Random Sample", fill=I("blue"), colour=I("black"), geom="histogram") w ##Density Curve
2011 Jul 25
1
two sample histogram
dear all, i am anewcomer. i have a set of paired data, the values are great different from each other. i want to show them in histogram. first, how to draw each bar for corresponding paired data side by side; second, how to set the scale of y axis? one is up to 100-fold to the other. ifdoubleslash is used to omit some coordinates, the histogram will looks better. is there anyone that can help
2008 Jul 08
4
Histogram with colors according to factor
Given a data frame with a continuous variable and a factor. I would like to generate a histogram of the continuous variable, where each bar is filled with different colors according to the percentage of factor values falling into this region of the continuous variable. I looked into packages like 'lattice' and 'ggplot2'. Searching R-help revealed that 'histogram' is
2023 Jan 12
1
Reg: ggplot error
...get. I wonder if anybody would like to go through your whole code. 1. data seems to be read correctly ICUData <- read.csv(file = "ICUData.csv", stringsAsFactors = TRUE) ICUData.neuro <- ICUData[ICUData$surgery == "neuro",] 2. ggplot(ICUData, aes(x=ICUData.neuro$LOS)) + geom_histogram(aes(y=after_stat(density)), binwidth = 5, fill = "darkgrey") gives me error Error in `check_aesthetics()`: ! Aesthetics must be either length 1 or the same as the data (500): x Run `]8;;rstudio:run:rlang::last_error()rlang::last_error()]8;;` to see where the error occu...
2017 Dec 13
1
overlay two histograms ggplot
Hi all, How can I overlay these two histograms? ggplot(gg, aes(gg$Alz, fill = gg$veg)) + geom_histogram(alpha = 0.2) ggplot(tt, aes(tt$Cont, fill = tt$veg)) + geom_histogram(alpha = 0.2) thanks for any help! Elahe
2009 Aug 19
2
ggplot2 legend problem
...aving a problem generating the legend coloring appropriate to each distribution in the plot. Here is a test case to show my best (failed) effort so far: library(ggplot2) x <- data.frame(X=rnorm(1000, mean=0)) y <- data.frame(Y=rnorm(1000, mean=3)) xy <- cbind(x, y) g <- ggplot(xy) g + geom_histogram(aes(x=X), colour="black", binwidth = 0.1, fill = alpha("red", .5)) + geom_histogram(aes(x=Y), colour="black", binwidth = 0.1, fill = alpha("blue", .5)) + scale_fill_manual("Case", values = alpha(c("red","blue"), 0.5), lim...
2012 Aug 06
4
Overlay Histogram
Dear all, For two sets of random variables, say, x <- rnorm(1000, 10, 10) and y <- rnorm(1000. 3, 20). Is there any way to overlay the histograms (and density curves) of x and y on the plot of y vs. x? The histogram of x is on the x axis and that of y is on the y axis. The density curve here is to approximate the shape of the distribution and does not have to have area 1. Thank you
2010 Jul 29
2
ggplot2 histograms... a subtle error found
...lowing for ggplot2 to decide the binwidths itself, I get the following error: - stat_bin: binwidth defaulted to range/30. Use 'binwidth = x' to adjust this. - Error: position_stack requires constant width My code is simply: ggplot(data=myDataSet, aes(x=myVarOI)) + geom_histogram() or qplot(myDataSet$myVarOI) If I go ahead and set the binwidth to some value, then the plot can be made without problems. The problem is with the specific data that it is trying to plot. I suspect it is trying to create bins of different sizes, from the error code. Here are the basi...
2009 Feb 02
1
Broke ggplot...
..._flat_df, VADeaths_flat_tmp3) VADeaths_flat_df<-rbind(VADeaths_flat_df, VADeaths_flat_tmp4) bin_size<-15.0 ggplot(VADeaths_flat_df, aes(x = factor(Data), fill = factor(Person))) + geom_bar(position=position_dodge(width =(20)), binwidth=20) # or ggplot(VADeaths_flat_df, aes(x=factor(Data))) + geom_histogram(binwidth=20)    Thanks again for any feedback you provide. [[alternative HTML version deleted]]
2009 Jul 23
1
Another question on gplot
I am getting following strange error : library(sn) library(ggplot2) dat1 <- as.matrix(rsn(1000, 0, 1, 0))[,1] ggplot() + geom_histogram(aes(x = dat1, y = ..density.., fill = ..count..)) + xlab("Distribution") + scale_y_continuous("") Error: No data for layer Can anyone please tell me why it is coming? -- View this message in context: http://www.nabble.com/Another-question-on-gplot-tp24624709p2...
2007 Nov 08
1
ggplot2 facets as rows and columns
...(g),x) require(lattice) histogram( ~ x | system, data = TDBU, xlab = "LRR Effect Size",type="density", panel = function(x, ...) { panel.histogram(x, ...) panel.densityplot(x,...) } ) library(ggplot2) ggplot(TDBU,aes(x=x))+geom_histogram(aes(y=..density..))+ geom_density()+facet_grid(system~.) -- View this message in context: http://www.nabble.com/ggplot2-facets-as-rows-and-columns-tf4771000.html#a13647294 Sent from the R help mailing list archive at Nabble.com.
2013 Jul 25
1
GGplot 2 – cannot get histogram and box plot axis to match.
...ggplot(dataSet,aes_string(x = "MPG.city",y = "MPG.city")) theBoxPlot = theBoxPlot + geom_boxplot() + expand_limits(y= graphRange) + coord_flip() print(theBoxPlot) #making the histogram thePlot <- ggplot(dataSet,aes_string(x = "MPG.city")) thePlot <-thePlot + geom_histogram() + expand_limits(x= graphRange) print(thePlot) Thank you for taking the time to read this. John Clow UCSB Student
2010 Nov 30
2
ggplot2 histograms
Hi With ggplot2 I can very easily create beautiful histograms but I would like to put two histograms on the same plot. The histograms may be over-lapping. When they are overlapping the bars are shown on top of each other (so that the overall height is the sum of the two). Is there any way to get them to display overlapping (with smaller value in front, larger value behind) so that the overall
2009 Sep 02
2
Howto fit normal curve into histogram using GGPLOT2
Currently, I am doing it this way. x <- mtcars$mpg h<-hist(x, breaks=10, col="red", xlab="Miles Per Gallon", main="Histogram with Normal Curve") xfit<-seq(min(x),max(x),length=40) yfit<-dnorm(xfit,mean=mean(x),sd=sd(x)) yfit <- yfit*diff(h$mids[1:2])*length(x) lines(xfit, yfit, col="blue", lwd=2) But since, ggplot2 has more appealing
2016 Jul 13
2
par() y ggplot2
Hola. Tengo 4 gráficos: a <- qqnorm(total$ImpTotal) #con lattice y b, c y d son variaciones de este tipo?, creados con ggplot2: ?b <- g <- ggplot(data = total, aes(x=ImpTotal, fill=Convenio)) g + geom_histogram(binwidth = 90) ? Los quiero representar de la forma: par(mfrow=c(2,2)) a b c d Pero los que crea con ggplot2 aparecen en par(mfrow=c(1,1)), es decir: ignora la instrucción. ¿No puedo forzar a ggplot2 a que me haga caso? ¿El problema radica en utilizar dos paquetes gráficos distintos? ¿Cuál sería la...
2010 Jan 18
2
ggplot2 histogramm
...f the "fill" (colour) legend and the defintion of "levels". Have anybody a hint how i can do this. df <- data.frame(variable=sample(c("A","B","C"),1000,replace=T,prob=c(0.22,0.28,0.5)),group=gl(2,500)) p <- ggplot(df, aes(x = variable)) p + geom_histogram(aes(y= ..count.. / sum(..count..),fill=..count../sum(..count..)*100)) + scale_y_continuous(formatter = "percent") + facet_wrap(~group) + ylab("Anteil in %") + xlab("Attribute") + opts(title="Title",legend.text="Anteil in Prozent") + BaseThem...