How to enter such a function into Deducer package

73 views
Skip to first unread message

Fadi Fouad Al-Sammak

unread,
Mar 26, 2012, 5:06:12 AM3/26/12
to Deducer
I want to know how can I enter the below function which is a very
useful function to mark the very ends of whiskers of the boxplots in
gggplot2 under R (get_tails function) into the dialog box of Deducer
package. Hint, the dialog box is under the geometric elements - points
- e.g. x = drv y=hwy (for reproducibility), summary, options change to
custom, there you would find a dialog box to enter a function
Load the library

library(Deducer)

data(mpg)

>#Create a function to calculate the points

>#a built-in function that does this

>get_tails = function(x) {

>q1 = quantile(x)[2]

>q3 = quantile(x)[4]

>iqr = q3 -q1

>upper = q3+1.5*iqr

>lower = q1-1.5*iqr

>#Trim upper and lower

>up = max(x[x < upper])

>lo = min(x[x > lower])

>return(c(lo, up)

>}

library(ggplot2) ggplot(mpg, aes(x=drv,y=hwy)) +
geom_boxplot( width=0.5) + stat_summary(geom="point", fun.y=
get_tails, pch=4, size=3, colour="red")

Please how can one enter such a nice function into the Deducer
package. Thanks in advance

Helios De Rosario

unread,
Mar 26, 2012, 5:25:55 PM3/26/12
to Deducer
Hi, Fadi.

In the Plot Builder, select boxplot in the tab "Geometric Elements",
and choose the X and Y variables as suitable (you can also set the
width of the box in the "Options" tab of the boxplot).

Then add a layer with "summary" from the tab "Statistics". The default
geom is "pointrange" (you'll see it in a combo box); change it to
"point", and set the aesthetics you want (plus the X, Y variables). In
the "Options" tab of this layer, change "Method" to "Custom", and in
the "y function" box write the name of your function (get_tails).

That works for me. Then, if you are going to repeat this plot often,
you can save it as a template (Tools > Make Template), and re-use it
as explained in the Deducer manual.

Hope it helps.

Helios

ffsa...@gmail.com

unread,
Mar 27, 2012, 5:08:29 AM3/27/12
to ded...@googlegroups.com
Thanks a lot for the help, it worked. My question, can we enter the whole code lines in Deducer instead of only just the name. I wonder why is it that the developer didn't include a small box to include the whole code lines of any function and let there be many functions to call from Deducer instead of repeatedly writing the function again outside the Deducer console? Is there any possibility to see like this box in the future?

best regards

Ian Fellows

unread,
Mar 27, 2012, 3:12:29 PM3/27/12
to ded...@googlegroups.com
Sure, you can just put:

function(x) {
q1 = quantile(x)[2]
q3 = quantile(x)[4]
iqr = q3 -q1
upper = q3+1.5*iqr
lower = q1-1.5*iqr

##Trim upper and lower


up = max(x[x < upper])
lo = min(x[x > lower])

return(c(lo, up))
}

in the box instead of get_tails.

Best,
Ian

ffsa...@gmail.com

unread,
Mar 31, 2012, 4:57:43 PM3/31/12
to ded...@googlegroups.com
Thanks Ian for the hint, I did enter the code in the y function box but the plot didn't appear, just the screen went plotting.. but no image. It worked when I copy the whole ggplot2 code in Tools > view call and then paste it in the JGR console the image appeared of course in a separate window. So why is that? and what shall I do to get things get smoother without the copy paste thing?  Thanks in advance


On Tuesday, March 27, 2012 9:12:29 PM UTC+2, Ian wrote:
Sure, you can just put:

function(x) {
 q1 = quantile(x)[2]
 q3 = quantile(x)[4]
 iqr = q3 -q1
 upper = q3+1.5*iqr
 lower = q1-1.5*iqr

 ##Trim upper and lower
 up = max(x[x < upper])
 lo = min(x[x > lower])

 return(c(lo, up))
}

in the box instead of get_tails.

Best,
Ian

Helios De Rosario

unread,
Apr 1, 2012, 1:52:51 PM4/1/12
to Deducer
On 31 mar, 22:57, ffsam...@gmail.com wrote:
> Thanks Ian for the hint, I did enter the code in the y function box but the
> plot didn't appear, just the screen went plotting.. but no image. It worked
> when I copy the whole ggplot2 code in Tools > view call and then paste it
> in the JGR console the image appeared of course in a separate window. So
> why is that? and what shall I do to get things get smoother without the
> copy paste thing?  Thanks in advance

"Copy-and-paste" is not really needed. Just press the "Run" button,
and the plot you want will be generated. However, it's true that the
preview doesn't work correctly in this case, and that's a problem.
Until Ian or another person finds the cause of this issue, I'd
recommend you define the function in the command line interface, and
write the name of the function in the dialog box.

Helios
Reply all
Reply to author
Forward
0 new messages