search for: aes_str

Displaying 20 results from an estimated 28 matches for "aes_str".

Did you mean: as_str
2009 Oct 02
1
ggplot2: proper use of facet_grid inside a function
Hello Again R Folk: I have found items about this in the archives, but I?m still not getting it right. I want to use ggplot2 with facet_grid inside a function with user specified variables, for instance: p <- ggplot(data, aes_string(x = fac1, y = res)) + facet_grid(. ~ fac2) Where data, fac1, fac2 and res are arguments to the function. I have tried p <- ggplot(data, aes_string(x = fac1, y = res)) + facet_grid(. ~ as.name(fac2)) and p <- ggplot(data, aes_string(x = fac1, y = res)) + facet_grid(?. ~ fac2?)...
2011 Aug 15
1
ggplot in a function confusion!
...o I plot within a function where I can feed the function a data.frame and the columns I want plotted? I assume this is some interesting name space issue but if you guys can enlighten me as to what's going on... Thanks, Justin P.S. So before I sent this I dug some more and found my answer, aes_string: plot.func<-function(dff,x.var,y.var){ print(ggplot() + geom_point(data=dff,aes_string(x=x.var,y=y.var))) } plot.func(df,'x','y') works great. But I still wouldn't mind some clarification on what's happening in my earlier examples. [[alternative HTML version...
2013 Jul 25
1
GGplot 2 – cannot get histogram and box plot axis to match.
...calculate the range to extend the axis dataVector <- unlist(dataSet[,"MPG.city"]) dataRange <- max(dataVector) - min(dataVector) graphRange <- c(min(dataVector) - dataRange/5, max(dataVector) + dataRange/5) #making the box plot theBoxPlot <- 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() + exp...
2007 Dec 13
2
use ggplot in a function to which a column name is given
Hi everyone, Hi ggplot users in particular, ggplot makes it very easy to plot things given their names when you use it interactively (and therefore can provide the names of the columns). qplot(x,foo,data=A) where A has columns (x,y,foo,bar) for example but I would like to use this from inside a function to which the name of the column is given. I cannot find an elegant way to make this
2008 Mar 25
2
ggplot2 - facetting
...lt;-data.frame(x=rep((1:4),4), y=rep(0.1*(1:4),4), group=sample(factor(rep(1:4,rep(4,4)), labels=c('Class1', 'Class2', 'Class3', 'Class4')))) plotdata2 <- plotdata2[order(plotdata2[,'group']),] plot0<-ggplot() layer1<-layer(data=plotdata2, mapping=aes_string(x='x',y='y'),geom='point', stat='identity') scaleY<-scale_y_continuous() scaleX <- scale_x_continuous() Facets<-facet_grid(group ~ .) plot1<-plot0+layer1 +scaleY + scaleX + facet_grid(group~.) plot1 I always get the error message: Error in check_form...
2008 Mar 26
2
ggplot2 argument handling odd
Hello there, I'm trying to do lots of plots in one for-loop. But somehow ggplot does not evaluate arguments as expected. Here is an example: library(lattice) library(ggplot2) pl <- list() pl2 <- list() cDat <- as.data.frame(cbind(x1=0:100,x2=0:10,x3=1:20)) for(obs in c("x1", "x2")) { pl[[obs]] <- xyplot(cDat[,obs] ~ cDat[,"x3"], main=obs)
2007 Dec 11
2
ggplot - Setting the y-scale in a bar plot
.... But I do not seem to find out how to fix the scale of the y-axis in this case. Any tips? Using R 2.6.1 on Windows. Thanks for any help, Pedro I attach below the code I am using: plotdata<-data.frame(x=factor(2:8), y=0.1*(2:8)) plot1<-ggplot() plot1<-plot1+layer(data=plotdata, mapping=aes_string(x='x',y='y'),geom='bar', stat='identity') RangeY <-c(0,1) YBreaks <- (0:10)*diff(RangeY)/10 YTickLabels<- as.character(YBreaks) plot2 <- plot1 + scale_y_continuous(limits=RangeY, breaks=YBreaks, labels=YTickLabels, expand=c(0,0)) print(plot2)
2007 Oct 13
1
geom_errorbar with ggplot2
...o be a continuous line linking the different bars. I attach below the code I used, as well as the data. ================================================================ DFrame<-data.frame(x=1:10,y=0.5*(1:10),Upper=(1:10)+0.5, Lower=(1:10)-0.5) p <- ggplot() l1<-layer(data=DFrame, mapping=aes_string(x='x',min='Lower', max='Upper'), geom='errorbar', stat='identity') p<-p + l1 + scale_y_continuous() p ======================================== I wonder if anyone can help me with this. Best, Pedro de Barros
2007 Oct 31
1
reversing the scale on ggplot
Dear All, I am trying to build a simple ggplot, but where the scale is reversed, i.e. the largest numbers are on the bottom. An example of the code I am using is > plotdata<-data.frame(x=1:10, y=runif(10)) > plot<-ggplot() > plot<-plot+layer(data=plotdata, mapping=aes_string(x='x',y='y'), geom='point', stat='identity', size=4) > plot<-plot+ scale_y_continuous(limits=c(1,0)) > print(plot) I was hoping that by reversing the limits argument I would obtain the result I wanted, but to no avail. I have searched the ggplot help...
2011 May 26
1
Question about ggplot2
Hi all, Is there any way for me to to string in the argument of qplot or ggplot? for example qplot(x='carat',y='price',data=diamonds,geom=c('point','smooth')) instead of qplot(x=carat,y=price,data=diamonds,geom=c('point','smooth')) Thanks!! Regards, TszKin Julian [[alternative HTML version deleted]]
2013 Nov 04
1
ggplot2: Add '+' operator for aes (uneval) objects
Dear all, Is there a reason, why there is no +-operator for aes (i.e. uneval) objects (as there is for themes and gg objects)? I had a couple of cases where such an operator would be useful, for instance to combine the result of aes and aes_string in functions. Any flaws with the following proposition: `+.uneval` <- function(e1, e2) { dup <- names(e1) %in% names(e2) if (any(dup)) { duplist <- paste(sQuote(names(e1)[dup]), collapse = ", ") msg <- sprintf(ngettext(length(dup), "ele...
2007 Nov 01
1
ggplot2 - expand range?
...e the axes cross exactly at (0,0). I tried using scale_y_continuous(limits=c(0,10)), but I always get an extra space at the bottom of the axes. The code I used is below. > plotdata<-data.frame(x=1:10, y=runif(10)) > plot<-ggplot() > plot<-plot+layer(data=plotdata, mapping=aes_string(x='x',y='y'), geom='point', stat='identity', size=4) > plot<-plot+ scale_y_continuous(limits=c(0,1)) > print(plot) I believe there may be a way to use expand_range to fix this (I think I read about it somewhere), but I do not seem to find out how. I...
2009 Dec 11
0
ggplot2: version 0.8.4
...the nearly 500 examples of ggplot in use. If you're interested, you can also sign up to the ggplot2 mailing list at http://groups.google.com/group/ggplot2, or track development at http://github.com/hadley/ggplot2 ggplot2 0.8.4 (2009-12-08) ---------------------------------------- * aes and aes_string both convert prefixes to full names * aesthetics: corrected list of aesthetics to include american spelling of colour as well as base R abbreviations * aesthetics: fix bug in detecting which aesthetics are calculated * aes_string treats NULL as "NULL" * annotate now works with missin...
2009 Dec 11
0
ggplot2: version 0.8.4
...the nearly 500 examples of ggplot in use. If you're interested, you can also sign up to the ggplot2 mailing list at http://groups.google.com/group/ggplot2, or track development at http://github.com/hadley/ggplot2 ggplot2 0.8.4 (2009-12-08) ---------------------------------------- * aes and aes_string both convert prefixes to full names * aesthetics: corrected list of aesthetics to include american spelling of colour as well as base R abbreviations * aesthetics: fix bug in detecting which aesthetics are calculated * aes_string treats NULL as "NULL" * annotate now works with missin...
2007 Dec 17
1
ggplot-How to define fill colours?
...======================================= my code: >plotdata1<-data.frame(x=rep(factor(1:4),4), y=rep(0.1*(1:4),4), +group=as.character(rep(c('white', 'red', 'blue', 'green'),rep(4,4)))) >plot0<-ggplot() >plot3<-plot0+layer(data=plotdata1, mapping=aes_string(x='x',y='y', +fill='group'),geom='bar', stat='identity', position='stack') >print(plot3)
2017 Apr 28
2
ggplot dentro de una función
Hola a todos, Partiendo de: library(ggplot2); library(data.table) datos <- data.table(Date = seq.Date(as.Date("2017-01-01"), as.Date("2017-01-10"), by = "day"), V1 = rnorm(10), V2 = rnorm(10)) Quiero crear una función para pintar un gráfico cuyos argumentos sean
2009 Mar 05
1
Using vectors of names in calls for functions
Dear R people, it is a pleasure to try and use functionnalities that are in ggplot, even with my poor capacities in R. so far, i'dlike to be able to use these in my own function, and to "be able to use it repeatedly from vectors where I store the names of my columns." I have understood that this is a very discussed topic, that many post have been exhanged but I cannot understand
2008 Mar 23
2
ggplot2 - legend for fill coulours
...90 14 2 0.2 grey60 15 3 0.3 grey10 16 4 0.4 grey10 > levels(plotdata2$group) [1] "grey10" "grey30" "grey60" "grey90" > as.numeric(plotdata2$group) [1] 2 2 1 4 2 3 3 4 3 1 4 2 4 3 1 1 Code: plot0<-ggplot() layer1<-layer(data=plotdata2, mapping=aes_string(x='x',y='y', fill='group'),geom='bar', stat='identity', position='stack') scaleFill<-scale_fill_identity(labels=levels(plotdata2$group), guide='tile', name='Group') scaleY<-scale_y_continuous(limits=c(0,4), expand=c(0,0)) pl...
2008 Feb 15
1
ggplot2 used in a function - variable scope/environment
Hi everybody! I'm trying to use ggplot2 to return a plot from a function (so I can add something or alter it then). Unfortunately, if I add a mapping to a layer in the function, the variable *name* is stored in the layer, rather than the variable's *value* - so that after the function returns the ggplot2-object, it doesn't plot because the variable don't exist in the
2007 Sep 02
0
ggplot2 - version 0.5.5
...at_density for creating stacked/conditional density plots * added parameters to geom_boxplot to control appearance of outlying points * overriding aesthetics with fixed values that have already been set with aesthetics now actually works * slightly better names for xaxis and yaxis grobs * added aes_string function to make it easier to construction aesthetic mapping specifications in functions * continuous scales now have labels argument so that you can manually specify labels if desired * stat_density now calculates densities on a common grid across groups. This means that position_fill and po...