search for: binwidth

Displaying 20 results from an estimated 50 matches for "binwidth".

2000 Jul 28
2
Loop removal?
Dear all, I've got a quite large dataframe (stor) with rows subject and rt (reaction time). I would like to split the reaction times per subject into 6 bins of equal size. Right now, I'm using the following code: bindata <- function(rt) { bindata <- rep(-1,length(rt)) binwidth <- length(rt)/6 bindata[order(rt)[(0*binwidth)+1:(1*binwidth)]] <- 1 bindata[order(rt)[(1*binwidth)+1:(2*binwidth)]] <- 2 bindata[order(rt)[(2*binwidth)+1:(3*binwidth)]] <- 3 bindata[order(rt)[(3*binwidth)+1:(4*binwidth)]] <- 4 bindata[order(rt)[(4*binwidth)+1:(5*binwidth)...
2009 Mar 02
3
ways to put multiple graphs on single page (using ggplot2)
Hi, Here are three plots: library(ggplot2) data(diamonds) randind <- sample(nrow(diamonds),1000,replace=FALSE) dsmall <- diamonds[randind,] qplot(carat, data=dsmall, geom="histogram",binwidth=1) qplot(carat, data=dsmall, geom="histogram",binwidth=.1) qplot(carat, data=dsmall, geom="histogram",binwidth=.01) What are ways to put these three plots on a single page and label them A, B, and C. In general, do you use R directly for these tasks, or do you use an image edi...
2010 Feb 05
1
histogram scott
Dear all, I want to use the histogtam as a density estimator, with the binwidths calculated using scott's formula which is binwidth = 3.49*ST.dev.*n^(-1/3) for the following data  (30 data points) 12-9-3-6-1-23-21-7-18-16-15-4-19-22-20-2-3-18-8-10-1-7-5-4-11-12-3-9-19-7 so first,I' ve tried this manually, and substituted in the above formula and I got st.dev.=7.02745 a...
2010 Jul 29
2
ggplot2 histograms... a subtle error found
Hello all, I have a peculiar and particular bug that I stumbled across with ggplot2. I cannot seem to replicate it with anything other than my specific data set. Here is the problem: - when I try to plot a histogram, allowing 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$myVarO...
2015 Jun 16
4
Ayuda boxplot ggplot2
...a escala en el eje Y, es decir, que las dos lleguen a 60? Adjunto el boxplot y a continuación el código que usé para producirlo. vplayout <- function(x, y) viewport(layout.pos.row = x, layout.pos.col = y) tor<-ggplot(parasitos, aes(x=Arrenurus, y = torax, fill= Arrenurus)) + geom_boxplot(binwidth = 2) + scale_fill_manual(values = c("lightgreen", "lightblue"))+ ylab("Total parásitos")+ xlab("")+ ggtitle("Parásitos en el tórax") abd<- ggplot(parasitos, aes(x=Arrenurus, y = abdomen, fill= Arrenurus)) + geom_boxplot(binwidth = 2) + sca...
2009 Feb 02
1
Broke ggplot...
..._flat_tmp1, VADeaths_flat_tmp2) VADeaths_flat_df<-rbind(VADeaths_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]]
2023 Jan 12
1
Reg: ggplot error
...hrough 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 occurred. which, I believe, resulted fro...
2009 Jan 03
2
R Stacked Histogram
I've seen this asked, but never fully answered.  Is it possible to plot stacked histograms in R? I have four data sets that I would like to show combined vertically in histogram format.  Is this possible?  Thank you for any feedback you can provide. P.S. I know I can show the four sets side by side, but I want to combine them, but still uniquely identify each.   Thanks again.
2009 Dec 10
1
barplot and cumulative curve using ggplot2 layers
...m left side and cumulative curve from right side in one graph itself using layers in ggplot2. I sorted the recruits 1st in decreasing order and then used mydata <- data.frame(jobno, recruits) ggplot(mydata, aes(x = jobno, y = recruits)) + geom_bar() but I am getting an error "stat_bin: binwidth defaulted to range/30. Use 'binwidth = x' to adjust this. Error in pmin(y, 0) : object "y" not found" Can someone guide me regarding this? How to get barplot from left side and cumulative curve from right side in one graph itself. Thanks in advance Regards Sunita -- View t...
2011 Jul 25
4
ggplot question: changing the label for the Y axis on a histogram
Some help with how to re-label the vertical axis in a histogram would be appreciated. qplot(off.sc,weight=rel.freq,binwidth=.29,main="test Figure"+ylab("New from inside"))+ylab("New from outside")+ xlab("off.sc\nAggregated frequency plots for 17 equal intervals.") The code produces a proper histogram. However, the y...
2010 Nov 30
2
ggplot2 histograms
...4,4,4,5,5,5,5,5,6,6,6,6,7,7,7,8,8,9,6,7,7,8,8,8,9,9,9,9,10,10,10,10,10,11,11,11,11,12,12,12,13,13,14,15,15,16,16,16,17,17,17,17,18,18,18,18,18) d2<-c(rep("a",25), rep("b",39)) dafr<-data.frame(d1,d2) library(ggplot) qplot(d1, data=dafr, fill=d2, geom='histogram', binwidth = 1) Many thanks for any help Sandy Sandy Small Clinical Physicist NHS Forth Valley and NHS Greater Glasgow and Clyde ******************************************************************************************************************** This message may contain confidential information. If yo......
2009 Aug 19
2
ggplot2 legend problem
...opriate 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), limits=c("A", "B")) + op...
2009 Apr 22
1
converting histogram to barchart
...There is basically two things to solve. 1. Covert histogram to a barplot 2. Convert polygon to line. Here is the code so far with comments. weights$Weight is the individual weight observations. Best regards. # calucate the right breakpoints breakpoints <- seq(min(weights), max(weights), by=binwidth) #scale density dens <- density(reference) dens$y <- dens$y * (length(weights$Weight)*binwidth) #graph it hist(weights$Weight, freq=TRUE, breaks=breakpoints, xlab=xlabel, ylab="No of Births", main=titles[i]) polygon(dens$x, dens$y, border=NA, col="grey60") #direct into...
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
2013 Jan 24
4
Difference between R and SAS in Corcordance index in ordinal logistic regression
lrm does some binning to make the calculations faster. The exact calculation is obtained by running f <- lrm(...) rcorr.cens(predict(f), DA), which results in: C Index Dxy S.D. n missing 0.96814404 0.93628809 0.03808336 32.00000000 0.00000000 uncensored Relevant Pairs Concordant Uncertain 32.00000000
1998 Jul 07
2
S speedup in R
...h some real code. This original version works: cif<-function(x, y, tau, h=tau[2]-tau[1]) { # conditional cross-intensity function for two point process realizations. # estimated at tau. # x and y are vectors of event times (sorting is not necessary). # tau is the lag (or vector of lags) # h is binwidth. # see Brillinger, Bryant, & Segundo (1976) eq 13, mhatAB(u) n <- length(x) cif.numerator <- NULL for(tt in tau) { point.counter <- sum(round(rank(c(x + tt + h/2, y))[1:n], 0) - round(rank(c(x + tt - h/2, y))[1:n], 0)) cif.numerator <- c(cif.numerator,point.counter) } cif.numer...
2009 Nov 14
2
formatting dates in axis labels (ggplot2)
...A coxcomb plot = bar chart + polar coordinates cxc1 + coord_polar(start=3*pi/2) + opts(title="Causes of Mortality in the Army in the East") + xlab("") # why doesn't this work? cxc1 <- cxc1 + scale_x_date(format="%b %Y", major="months") cxc1 stat_bin: binwidth defaulted to range/30. Use 'binwidth = x' to adjust this. OK, I tried formatting Date first, in different ways. Each time, I get a graphical result, but I don't know how to use format() for dates to make the result ordered as normal dates, rather than as character strings. Night1$d...
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 función...
2008 Jan 15
4
Overlay plots from different data sets using the Lattice package
#After spending the entire day working on this question, I have decided to reach out for support: #I am trying to overlay a densityplot from one data set over a histogram of another, if I were to plot the two individually, they would look like: # data frame construction data.frame.A <- data.frame(rnorm(12*8), c(rep("one", 4), rep("two", 4), rep("three", 4)),
2009 Jul 13
1
Strange error in qplot
Hi all, whenever I try to plot a histogram using qplot() function of "ggplot2" library, I get error like this : > qplot(rnorm(1000), geom="histogram", binwidth=0.2, main = "", xlab="", > ylab="") Error in scale[[1]] : subscript out of bounds However if I remove ylab="" argument, then it is working fine. Am I missing something? Regards, -- View this message in context: http://www.nabble.com/Strange-error-in-qpl...