ggplot inside function doesn't plot

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

ggplot inside function doesn't plot

Ed Siefker
I have a function:

myplot <- function (X) {
    d <- plotCounts(dds2, gene=X, intgroup="condition", returnData=TRUE)
    png(paste("img/", X, ".png", sep=""))
    ggplot(d, aes(x=condition, y=count, color=condition)) +
        geom_point(position=position_jitter(w=0.1,h=0)) +
        scale_y_log10(breaks=c(25,100,400)) +
        ggtitle(X) +
        theme(plot.title = element_text(hjust = 0.5))

    dev.off()
    }

'd' is a dataframe

                             count      condition
E11.5 F20HET BA40_quant   955.9788   E11.5 F20HET
E11.5 F20HET BA45_quant   796.2863   E11.5 F20HET
E11.5 F20HET BB84_quant   745.0340   E11.5 F20HET
E11.5 F9.20DKO YEH3_quant 334.2994 E11.5 F9.20DKO
E11.5 F9.20DKO fkm1_quant 313.7307 E11.5 F9.20DKO
E11.5 F9.20DKO zzE2_quant 349.3313 E11.5 F9.20DKO

If I set X="Etv5" and paste the contents of the function into R, I get
'img/Etv5.png'
If I run myplot(X), I get nothing.


> X
[1] "Etv5"
> list.files("img")
character(0)
> myplot(X)
null device
          1
> list.files("img")
character(0)
> d <- plotCounts(dds2, gene=X, intgroup="condition", returnData=TRUE)
> png(paste("img/", X, ".png", sep=""))
> ggplot(d, aes(x=condition, y=count, color=condition)) +
+ geom_point(position=position_jitter(w=0.1,h=0)) +
+ scale_y_log10(breaks=c(25,100,400)) +
+ ggtitle(X) +
+ theme(plot.title = element_text(hjust = 0.5))
> dev.off()
null device
          1
> list.files("img")
[1] "Etv5.png"

Why doesn't my function work?

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: ggplot inside function doesn't plot

PIKAL Petr
Hi

You have to print it.

just add

print(all ggplot stuff)

inside the function.

Cheers
Petr

> -----Original Message-----
> From: R-help [mailto:[hidden email]] On Behalf Of Ed Siefker
> Sent: Thursday, November 2, 2017 5:27 PM
> To: r-help <[hidden email]>
> Subject: [R] ggplot inside function doesn't plot
>
> I have a function:
>
> myplot <- function (X) {
>     d <- plotCounts(dds2, gene=X, intgroup="condition", returnData=TRUE)
>     png(paste("img/", X, ".png", sep=""))
>     ggplot(d, aes(x=condition, y=count, color=condition)) +
>         geom_point(position=position_jitter(w=0.1,h=0)) +
>         scale_y_log10(breaks=c(25,100,400)) +
>         ggtitle(X) +
>         theme(plot.title = element_text(hjust = 0.5))
>
>     dev.off()
>     }
>
> 'd' is a dataframe
>
>                              count      condition
> E11.5 F20HET BA40_quant   955.9788   E11.5 F20HET
> E11.5 F20HET BA45_quant   796.2863   E11.5 F20HET
> E11.5 F20HET BB84_quant   745.0340   E11.5 F20HET
> E11.5 F9.20DKO YEH3_quant 334.2994 E11.5 F9.20DKO
> E11.5 F9.20DKO fkm1_quant 313.7307 E11.5 F9.20DKO
> E11.5 F9.20DKO zzE2_quant 349.3313 E11.5 F9.20DKO
>
> If I set X="Etv5" and paste the contents of the function into R, I get
> 'img/Etv5.png'
> If I run myplot(X), I get nothing.
>
>
> > X
> [1] "Etv5"
> > list.files("img")
> character(0)
> > myplot(X)
> null device
>           1
> > list.files("img")
> character(0)
> > d <- plotCounts(dds2, gene=X, intgroup="condition", returnData=TRUE)
> > png(paste("img/", X, ".png", sep="")) ggplot(d, aes(x=condition,
> > y=count, color=condition)) +
> + geom_point(position=position_jitter(w=0.1,h=0)) +
> + scale_y_log10(breaks=c(25,100,400)) +
> + ggtitle(X) +
> + theme(plot.title = element_text(hjust = 0.5))
> > dev.off()
> null device
>           1
> > list.files("img")
> [1] "Etv5.png"
>
> Why doesn't my function work?
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

________________________________
Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a jsou určeny pouze jeho adresátům.
Jestliže jste obdržel(a) tento e-mail omylem, informujte laskavě neprodleně jeho odesílatele. Obsah tohoto emailu i s přílohami a jeho kopie vymažte ze svého systému.
Nejste-li zamýšleným adresátem tohoto emailu, nejste oprávněni tento email jakkoliv užívat, rozšiřovat, kopírovat či zveřejňovat.
Odesílatel e-mailu neodpovídá za eventuální škodu způsobenou modifikacemi či zpožděním přenosu e-mailu.

V případě, že je tento e-mail součástí obchodního jednání:
- vyhrazuje si odesílatel právo ukončit kdykoliv jednání o uzavření smlouvy, a to z jakéhokoliv důvodu i bez uvedení důvodu.
- a obsahuje-li nabídku, je adresát oprávněn nabídku bezodkladně přijmout; Odesílatel tohoto e-mailu (nabídky) vylučuje přijetí nabídky ze strany příjemce s dodatkem či odchylkou.
- trvá odesílatel na tom, že příslušná smlouva je uzavřena teprve výslovným dosažením shody na všech jejích náležitostech.
- odesílatel tohoto emailu informuje, že není oprávněn uzavírat za společnost žádné smlouvy s výjimkou případů, kdy k tomu byl písemně zmocněn nebo písemně pověřen a takové pověření nebo plná moc byly adresátovi tohoto emailu případně osobě, kterou adresát zastupuje, předloženy nebo jejich existence je adresátovi či osobě jím zastoupené známá.

This e-mail and any documents attached to it may be confidential and are intended only for its intended recipients.
If you received this e-mail by mistake, please immediately inform its sender. Delete the contents of this e-mail with all attachments and its copies from your system.
If you are not the intended recipient of this e-mail, you are not authorized to use, disseminate, copy or disclose this e-mail in any manner.
The sender of this e-mail shall not be liable for any possible damage caused by modifications of the e-mail or by delay with transfer of the email.

In case that this e-mail forms part of business dealings:
- the sender reserves the right to end negotiations about entering into a contract in any time, for any reason, and without stating any reasoning.
- if the e-mail contains an offer, the recipient is entitled to immediately accept such offer; The sender of this e-mail (offer) excludes any acceptance of the offer on the part of the recipient containing any amendment or variation.
- the sender insists on that the respective contract is concluded only upon an express mutual agreement on all its aspects.
- the sender of this e-mail informs that he/she is not authorized to enter into any contracts on behalf of the company except for cases in which he/she is expressly authorized to do so in writing, and such authorization or power of attorney is submitted to the recipient or the person represented by the recipient, or the existence of such authorization is known to the recipient of the person represented by the recipient.
______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: ggplot inside function doesn't plot

David Winsemius
In reply to this post by Ed Siefker

> On Nov 2, 2017, at 9:27 AM, Ed Siefker <[hidden email]> wrote:
>
> I have a function:
>
> myplot <- function (X) {
>    d <- plotCounts(dds2, gene=X, intgroup="condition", returnData=TRUE)
>    png(paste("img/", X, ".png", sep=""))
>    ggplot(d, aes(x=condition, y=count, color=condition)) +
>        geom_point(position=position_jitter(w=0.1,h=0)) +
>        scale_y_log10(breaks=c(25,100,400)) +
>        ggtitle(X) +
>        theme(plot.title = element_text(hjust = 0.5))
>
>    dev.off()
>    }
>
> 'd' is a dataframe
>
>                             count      condition
> E11.5 F20HET BA40_quant   955.9788   E11.5 F20HET
> E11.5 F20HET BA45_quant   796.2863   E11.5 F20HET
> E11.5 F20HET BB84_quant   745.0340   E11.5 F20HET
> E11.5 F9.20DKO YEH3_quant 334.2994 E11.5 F9.20DKO
> E11.5 F9.20DKO fkm1_quant 313.7307 E11.5 F9.20DKO
> E11.5 F9.20DKO zzE2_quant 349.3313 E11.5 F9.20DKO
>
> If I set X="Etv5" and paste the contents of the function into R, I get
> 'img/Etv5.png'
> If I run myplot(X), I get nothing.
>
>
>> X
> [1] "Etv5"
>> list.files("img")
> character(0)
>> myplot(X)
> null device
>          1
>> list.files("img")
> character(0)
>> d <- plotCounts(dds2, gene=X, intgroup="condition", returnData=TRUE)
>> png(paste("img/", X, ".png", sep=""))
>> ggplot(d, aes(x=condition, y=count, color=condition)) +
> + geom_point(position=position_jitter(w=0.1,h=0)) +
> + scale_y_log10(breaks=c(25,100,400)) +
> + ggtitle(X) +
> + theme(plot.title = element_text(hjust = 0.5))
>> dev.off()
> null device
>          1
>> list.files("img")
> [1] "Etv5.png"
>
> Why doesn't my function work?

`ggplot` creates an object. You need to print it when used inside a function. Inside a function (in a more restricted environment) there is no parse-eval-print-loop.


>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

David Winsemius
Alameda, CA, USA

'Any technology distinguishable from magic is insufficiently advanced.'   -Gehm's Corollary to Clarke's Third Law

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: ggplot inside function doesn't plot

Ed Siefker
I don't really understand. I mean, I understand the solution is
print(ggplot(...)).  But why is that required in a function and not at
the console?

Shouldn't I be able to rely on what I do at the console working in a
script?  Is this inconsistent behavior by design?



On Thu, Nov 2, 2017 at 11:54 AM, David Winsemius <[hidden email]> wrote:

>
>> On Nov 2, 2017, at 9:27 AM, Ed Siefker <[hidden email]> wrote:
>>
>> I have a function:
>>
>> myplot <- function (X) {
>>    d <- plotCounts(dds2, gene=X, intgroup="condition", returnData=TRUE)
>>    png(paste("img/", X, ".png", sep=""))
>>    ggplot(d, aes(x=condition, y=count, color=condition)) +
>>        geom_point(position=position_jitter(w=0.1,h=0)) +
>>        scale_y_log10(breaks=c(25,100,400)) +
>>        ggtitle(X) +
>>        theme(plot.title = element_text(hjust = 0.5))
>>
>>    dev.off()
>>    }
>>
>> 'd' is a dataframe
>>
>>                             count      condition
>> E11.5 F20HET BA40_quant   955.9788   E11.5 F20HET
>> E11.5 F20HET BA45_quant   796.2863   E11.5 F20HET
>> E11.5 F20HET BB84_quant   745.0340   E11.5 F20HET
>> E11.5 F9.20DKO YEH3_quant 334.2994 E11.5 F9.20DKO
>> E11.5 F9.20DKO fkm1_quant 313.7307 E11.5 F9.20DKO
>> E11.5 F9.20DKO zzE2_quant 349.3313 E11.5 F9.20DKO
>>
>> If I set X="Etv5" and paste the contents of the function into R, I get
>> 'img/Etv5.png'
>> If I run myplot(X), I get nothing.
>>
>>
>>> X
>> [1] "Etv5"
>>> list.files("img")
>> character(0)
>>> myplot(X)
>> null device
>>          1
>>> list.files("img")
>> character(0)
>>> d <- plotCounts(dds2, gene=X, intgroup="condition", returnData=TRUE)
>>> png(paste("img/", X, ".png", sep=""))
>>> ggplot(d, aes(x=condition, y=count, color=condition)) +
>> + geom_point(position=position_jitter(w=0.1,h=0)) +
>> + scale_y_log10(breaks=c(25,100,400)) +
>> + ggtitle(X) +
>> + theme(plot.title = element_text(hjust = 0.5))
>>> dev.off()
>> null device
>>          1
>>> list.files("img")
>> [1] "Etv5.png"
>>
>> Why doesn't my function work?
>
> `ggplot` creates an object. You need to print it when used inside a function. Inside a function (in a more restricted environment) there is no parse-eval-print-loop.
>
>
>>
>> ______________________________________________
>> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>
> David Winsemius
> Alameda, CA, USA
>
> 'Any technology distinguishable from magic is insufficiently advanced.'   -Gehm's Corollary to Clarke's Third Law
>
>
>
>
>

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: ggplot inside function doesn't plot

Richard M. Heiberger
FAQ 7.22

Open the file indicated by
system.file("../../doc/FAQ")
and scroll down to 7.22



On Thu, Nov 2, 2017 at 1:03 PM, Ed Siefker <[hidden email]> wrote:

> I don't really understand. I mean, I understand the solution is
> print(ggplot(...)).  But why is that required in a function and not at
> the console?
>
> Shouldn't I be able to rely on what I do at the console working in a
> script?  Is this inconsistent behavior by design?
>
>
>
> On Thu, Nov 2, 2017 at 11:54 AM, David Winsemius <[hidden email]> wrote:
>>
>>> On Nov 2, 2017, at 9:27 AM, Ed Siefker <[hidden email]> wrote:
>>>
>>> I have a function:
>>>
>>> myplot <- function (X) {
>>>    d <- plotCounts(dds2, gene=X, intgroup="condition", returnData=TRUE)
>>>    png(paste("img/", X, ".png", sep=""))
>>>    ggplot(d, aes(x=condition, y=count, color=condition)) +
>>>        geom_point(position=position_jitter(w=0.1,h=0)) +
>>>        scale_y_log10(breaks=c(25,100,400)) +
>>>        ggtitle(X) +
>>>        theme(plot.title = element_text(hjust = 0.5))
>>>
>>>    dev.off()
>>>    }
>>>
>>> 'd' is a dataframe
>>>
>>>                             count      condition
>>> E11.5 F20HET BA40_quant   955.9788   E11.5 F20HET
>>> E11.5 F20HET BA45_quant   796.2863   E11.5 F20HET
>>> E11.5 F20HET BB84_quant   745.0340   E11.5 F20HET
>>> E11.5 F9.20DKO YEH3_quant 334.2994 E11.5 F9.20DKO
>>> E11.5 F9.20DKO fkm1_quant 313.7307 E11.5 F9.20DKO
>>> E11.5 F9.20DKO zzE2_quant 349.3313 E11.5 F9.20DKO
>>>
>>> If I set X="Etv5" and paste the contents of the function into R, I get
>>> 'img/Etv5.png'
>>> If I run myplot(X), I get nothing.
>>>
>>>
>>>> X
>>> [1] "Etv5"
>>>> list.files("img")
>>> character(0)
>>>> myplot(X)
>>> null device
>>>          1
>>>> list.files("img")
>>> character(0)
>>>> d <- plotCounts(dds2, gene=X, intgroup="condition", returnData=TRUE)
>>>> png(paste("img/", X, ".png", sep=""))
>>>> ggplot(d, aes(x=condition, y=count, color=condition)) +
>>> + geom_point(position=position_jitter(w=0.1,h=0)) +
>>> + scale_y_log10(breaks=c(25,100,400)) +
>>> + ggtitle(X) +
>>> + theme(plot.title = element_text(hjust = 0.5))
>>>> dev.off()
>>> null device
>>>          1
>>>> list.files("img")
>>> [1] "Etv5.png"
>>>
>>> Why doesn't my function work?
>>
>> `ggplot` creates an object. You need to print it when used inside a function. Inside a function (in a more restricted environment) there is no parse-eval-print-loop.
>>
>>
>>>
>>> ______________________________________________
>>> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>
>> David Winsemius
>> Alameda, CA, USA
>>
>> 'Any technology distinguishable from magic is insufficiently advanced.'   -Gehm's Corollary to Clarke's Third Law
>>
>>
>>
>>
>>
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: ggplot inside function doesn't plot

Duncan Murdoch-2
In reply to this post by Ed Siefker
On 02/11/2017 1:03 PM, Ed Siefker wrote:
> I don't really understand. I mean, I understand the solution is
> print(ggplot(...)).  But why is that required in a function and not at
> the console?
>
> Shouldn't I be able to rely on what I do at the console working in a
> script?  Is this inconsistent behavior by design?

Yes, it's by design.  At top level, values are normally printed after
being computed (but this can be turned off).  So

x <- 5
x + 1

will print 6 after the second line.  If you have the line "x + 1" in a
function, nothing will print.  So you can have a function

addOne <- function(x) {
   x + 1
}

and you can call it lots of times from other functions without printing
a line each time.

Duncan Murdoch

>
>
>
> On Thu, Nov 2, 2017 at 11:54 AM, David Winsemius <[hidden email]> wrote:
>>
>>> On Nov 2, 2017, at 9:27 AM, Ed Siefker <[hidden email]> wrote:
>>>
>>> I have a function:
>>>
>>> myplot <- function (X) {
>>>     d <- plotCounts(dds2, gene=X, intgroup="condition", returnData=TRUE)
>>>     png(paste("img/", X, ".png", sep=""))
>>>     ggplot(d, aes(x=condition, y=count, color=condition)) +
>>>         geom_point(position=position_jitter(w=0.1,h=0)) +
>>>         scale_y_log10(breaks=c(25,100,400)) +
>>>         ggtitle(X) +
>>>         theme(plot.title = element_text(hjust = 0.5))
>>>
>>>     dev.off()
>>>     }
>>>
>>> 'd' is a dataframe
>>>
>>>                              count      condition
>>> E11.5 F20HET BA40_quant   955.9788   E11.5 F20HET
>>> E11.5 F20HET BA45_quant   796.2863   E11.5 F20HET
>>> E11.5 F20HET BB84_quant   745.0340   E11.5 F20HET
>>> E11.5 F9.20DKO YEH3_quant 334.2994 E11.5 F9.20DKO
>>> E11.5 F9.20DKO fkm1_quant 313.7307 E11.5 F9.20DKO
>>> E11.5 F9.20DKO zzE2_quant 349.3313 E11.5 F9.20DKO
>>>
>>> If I set X="Etv5" and paste the contents of the function into R, I get
>>> 'img/Etv5.png'
>>> If I run myplot(X), I get nothing.
>>>
>>>
>>>> X
>>> [1] "Etv5"
>>>> list.files("img")
>>> character(0)
>>>> myplot(X)
>>> null device
>>>           1
>>>> list.files("img")
>>> character(0)
>>>> d <- plotCounts(dds2, gene=X, intgroup="condition", returnData=TRUE)
>>>> png(paste("img/", X, ".png", sep=""))
>>>> ggplot(d, aes(x=condition, y=count, color=condition)) +
>>> + geom_point(position=position_jitter(w=0.1,h=0)) +
>>> + scale_y_log10(breaks=c(25,100,400)) +
>>> + ggtitle(X) +
>>> + theme(plot.title = element_text(hjust = 0.5))
>>>> dev.off()
>>> null device
>>>           1
>>>> list.files("img")
>>> [1] "Etv5.png"
>>>
>>> Why doesn't my function work?
>>
>> `ggplot` creates an object. You need to print it when used inside a function. Inside a function (in a more restricted environment) there is no parse-eval-print-loop.
>>
>>
>>>
>>> ______________________________________________
>>> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>
>> David Winsemius
>> Alameda, CA, USA
>>
>> 'Any technology distinguishable from magic is insufficiently advanced.'   -Gehm's Corollary to Clarke's Third Law
>>
>>
>>
>>
>>
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: ggplot inside function doesn't plot

David Winsemius
In reply to this post by Ed Siefker

> On Nov 2, 2017, at 10:03 AM, Ed Siefker <[hidden email]> wrote:
>
> I don't really understand. I mean, I understand the solution is
> print(ggplot(...)).  But why is that required in a function and not at
> the console?

The REPL design of the interactive console is offered the user as a convenience, but I agree it's somewhat at odds with pure functional principles.

>
> Shouldn't I be able to rely on what I do at the console working in a
> script?  Is this inconsistent behavior by design?

By design? Yes. Completely by design. Functions are a method of encapsulating intermediate results in a manner that does not interact with the objects that exist outside the function. There are three plotting paradigms: base-graphics, lattice, and ggplot. The latter two are built with grid graphics and a both more functional and object oriented (loosely spoken since they return objects) than base graphics. Base graphics behaves the way you expect. Execution of `lines` or `points` will give you "pen-on-ink" output, actually pixel on device output.


>
>
>
> On Thu, Nov 2, 2017 at 11:54 AM, David Winsemius <[hidden email]> wrote:
>>
>>> On Nov 2, 2017, at 9:27 AM, Ed Siefker <[hidden email]> wrote:
>>>
>>> I have a function:
>>>
>>> myplot <- function (X) {
>>>   d <- plotCounts(dds2, gene=X, intgroup="condition", returnData=TRUE)
>>>   png(paste("img/", X, ".png", sep=""))
>>>   ggplot(d, aes(x=condition, y=count, color=condition)) +
>>>       geom_point(position=position_jitter(w=0.1,h=0)) +
>>>       scale_y_log10(breaks=c(25,100,400)) +
>>>       ggtitle(X) +
>>>       theme(plot.title = element_text(hjust = 0.5))
>>>
>>>   dev.off()
>>>   }
>>>
>>> 'd' is a dataframe
>>>
>>>                            count      condition
>>> E11.5 F20HET BA40_quant   955.9788   E11.5 F20HET
>>> E11.5 F20HET BA45_quant   796.2863   E11.5 F20HET
>>> E11.5 F20HET BB84_quant   745.0340   E11.5 F20HET
>>> E11.5 F9.20DKO YEH3_quant 334.2994 E11.5 F9.20DKO
>>> E11.5 F9.20DKO fkm1_quant 313.7307 E11.5 F9.20DKO
>>> E11.5 F9.20DKO zzE2_quant 349.3313 E11.5 F9.20DKO
>>>
>>> If I set X="Etv5" and paste the contents of the function into R, I get
>>> 'img/Etv5.png'
>>> If I run myplot(X), I get nothing.
>>>
>>>
>>>> X
>>> [1] "Etv5"
>>>> list.files("img")
>>> character(0)
>>>> myplot(X)
>>> null device
>>>         1
>>>> list.files("img")
>>> character(0)
>>>> d <- plotCounts(dds2, gene=X, intgroup="condition", returnData=TRUE)
>>>> png(paste("img/", X, ".png", sep=""))
>>>> ggplot(d, aes(x=condition, y=count, color=condition)) +
>>> + geom_point(position=position_jitter(w=0.1,h=0)) +
>>> + scale_y_log10(breaks=c(25,100,400)) +
>>> + ggtitle(X) +
>>> + theme(plot.title = element_text(hjust = 0.5))
>>>> dev.off()
>>> null device
>>>         1
>>>> list.files("img")
>>> [1] "Etv5.png"
>>>
>>> Why doesn't my function work?
>>
>> `ggplot` creates an object. You need to print it when used inside a function. Inside a function (in a more restricted environment) there is no parse-eval-print-loop.
>>
>>
>>>
>>> ______________________________________________
>>> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>
>> David Winsemius
>> Alameda, CA, USA
>>
>> 'Any technology distinguishable from magic is insufficiently advanced.'   -Gehm's Corollary to Clarke's Third Law
>>
>>
>>
>>
>>
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

David Winsemius
Alameda, CA, USA

'Any technology distinguishable from magic is insufficiently advanced.'   -Gehm's Corollary to Clarke's Third Law

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.