[R] geom_segment drop unused levels

Jeff Newmiller jdnewmil at dcn.davis.CA.us
Tue Jul 7 15:45:09 CEST 2015


Sorry, now it works for me as well. And yes, must drop rows with is.na( prace ) prior to calling ggplot.  Note that the levels of prace  do not contain NA so your subject line is not correct.
---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil at dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
--------------------------------------------------------------------------- 
Sent from my phone. Please excuse my brevity.

On July 7, 2015 6:09:01 AM PDT, Thierry Onkelinx <thierry.onkelinx at inbo.be> wrote:
>I disagree with you Jeff. I can reproduce it without any problem.
>
>I see no other option than to remove the offending missing data prior
>to
>plotting.
>
>Best regards,
>
>ir. Thierry Onkelinx
>Instituut voor natuur- en bosonderzoek / Research Institute for Nature
>and
>Forest
>team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance
>Kliniekstraat 25
>1070 Anderlecht
>Belgium
>
>To call in the statistician after the experiment is done may be no more
>than asking him to perform a post-mortem examination: he may be able to
>say
>what the experiment died of. ~ Sir Ronald Aylmer Fisher
>The plural of anecdote is not data. ~ Roger Brinner
>The combination of some data and an aching desire for an answer does
>not
>ensure that a reasonable answer can be extracted from a given body of
>data.
>~ John Tukey
>
>2015-07-07 14:56 GMT+02:00 Jeff Newmiller <jdnewmil at dcn.davis.ca.us>:
>
>> Not reproducible.
>>
>---------------------------------------------------------------------------
>> Jeff Newmiller                        The     .....       .....  Go
>Live...
>> DCN:<jdnewmil at dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live
>> Go...
>>                                       Live:   OO#.. Dead: OO#.. 
>Playing
>> Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
>> /Software/Embedded Controllers)               .OO#.       .OO#. 
>rocks...1k
>>
>---------------------------------------------------------------------------
>> Sent from my phone. Please excuse my brevity.
>>
>> On July 7, 2015 12:44:20 AM PDT, PIKAL Petr <petr.pikal at precheza.cz>
>> wrote:
>> >Dear all.
>> >
>> >I want to drop unused (NA) level from geom_segment plot. I tried
>> >different combination of drop = TRUE argument in several places of
>> >following code but NA level of prace is still present.
>> >
>> >p<-ggplot(snimek, aes(x=cas, y=prace, xend=endtime, yend=prace,
>> >colour=typ, size=osoba))
>> >p+geom_segment(alpha=.4)+scale_size_discrete(range=c(3,6))+
>> >guides(colour = guide_legend(override.aes = list(size=4)))
>> >
>> >Is it possible to remove NA level directly from ggplot call or do I
>> >need to discard rows with NA before plotting?
>> >
>> >Below are data
>> >
>> >Best regards.
>> >Petr
>> >
>> >> dput(snimek)
>> >snimek <- structure(list(start = c(7.5, 8, 8.1, 8.4, 9.3, 10.45, 11,
>> >11.35,
>> >11.5, 12.25, 12.4, 13.2, 14.05, 14.2, 14.3, 7.55, 8, 8.1, 8.15,
>> >8.35, 9.1, 9.4, 10, 12.05, 12.25, 12.4, 13.35, 14.05, 14.2, 14.3
>> >), akce = structure(c(9L, 7L, 11L, 4L, 14L, 8L, 6L, 16L, 14L,
>> >2L, 15L, 10L, 2L, 8L, 5L, 12L, 7L, 13L, 7L, 18L, 7L, 3L, 7L,
>> >6L, 2L, 1L, 17L, 2L, 8L, 5L), .Label = c("Administrativa",
>"Cigareta",
>> >"CL vzorky", "Čištění MM", "Konec", "Oběd", "Počítač", "Přestávka",
>> >"Satna", "Sklad", "Svačina", "Šatna", "Tisk dokumentace", "Úklid",
>> >"Úklid výrobny", "Vymytí sudů", "Výstražné cedule", "Vzorkování"
>> >), class = "factor"), zarizeni = c(NA, NA, NA, NA, NA, NA, NA,
>> >NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
>> >NA, NA, NA, NA, NA, NA, NA), typ = structure(c(4L, 5L, 4L, 5L,
>> >5L, 4L, 2L, 5L, 5L, 1L, 5L, 5L, 1L, 4L, NA, 4L, 3L, 5L, 5L, 5L,
>> >5L, 5L, 5L, 2L, 1L, 5L, 5L, 1L, 4L, NA), .Label = c("Kouření",
>> >"Oběd", "Počítač", "Prostoj", "Režie"), class = "factor"), prace =
>> >structure(c(1L,
>> >2L, 1L, 4L, 2L, 1L, 1L, 2L, 2L, 1L, 3L, 2L, 1L, 1L, NA, 1L, 2L,
>> >3L, 2L, 3L, 2L, 3L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, NA), .Label =
>c("Ne",
>> >"Režie", "Výroba", "Výzkum"), class = "factor"), osoba =
>> >structure(c(1L,
>> >1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L,
>> >2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label =
>> >c("Bernát",
>> >"Červenka"), class = "factor"), cas = structure(list(sec = c(0,
>> >0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
>> >0, 0, 0, 0, 0, 0, 0, 0), min = c(50L, 0L, 10L, 40L, 30L, 45L,
>> >0L, 35L, 50L, 25L, 40L, 20L, 5L, 20L, 30L, 55L, 0L, 10L, 15L,
>> >35L, 10L, 40L, 0L, 5L, 25L, 40L, 35L, 5L, 20L, 30L), hour = c(7L,
>> >8L, 8L, 8L, 9L, 10L, 11L, 11L, 11L, 12L, 12L, 13L, 14L, 14L,
>> >14L, 7L, 8L, 8L, 8L, 8L, 9L, 9L, 10L, 12L, 12L, 12L, 13L, 14L,
>> >14L, 14L), mday = c(7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,
>> >7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,
>> >7L, 7L, 7L), mon = c(6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
>> >6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
>> >6L, 6L, 6L, 6L), year = c(115L, 115L, 115L, 115L, 115L, 115L,
>> >115L, 115L, 115L, 115L, 115L, 115L, 115L, 115L, 115L, 115L, 115L,
>> >115L, 115L, 115L, 115L, 115L, 115L, 115L, 115L, 115L, 115L, 115L,
>> >115L, 115L), wday = c(2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
>> >2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
>> >2L, 2L, 2L, 2L), yday = c(187L, 187L, 187L, 187L, 187L, 187L,
>> >187L, 187L, 187L, 187L, 187L, 187L, 187L, 187L, 187L, 187L, 187L,
>> >187L, 187L, 187L, 187L, 187L, 187L, 187L, 187L, 187L, 187L, 187L,
>> >187L, 187L), isdst = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
>> >1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
>> >1L, 1L, 1L, 1L), zone = c("CEST", "CEST", "CEST", "CEST", "CEST",
>> >"CEST", "CEST", "CEST", "CEST", "CEST", "CEST", "CEST", "CEST",
>> >"CEST", "CEST", "CEST", "CEST", "CEST", "CEST", "CEST", "CEST",
>> >"CEST", "CEST", "CEST", "CEST", "CEST", "CEST", "CEST", "CEST",
>> >"CEST"), gmtoff = c(NA_integer_, NA_integer_, NA_integer_,
>NA_integer_,
>> >NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
>> >NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
>> >NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
>> >NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
>> >NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
>> >NA_integer_)), .Names = c("sec", "min", "hour", "mday", "mon",
>> >"year", "wday", "yday", "isdst", "zone", "gmtoff"), class =
>> >c("POSIXlt",
>> >"POSIXt")), doba = c(10, 10, 30, 50, 75, 15, 35, 15, 35, 15,
>> >40, 45, 15, 10, NA, 5, 10, 5, 20, 35, 30, 20, 125, 20, 15, 55,
>> >30, 15, 10, NA), endtime = structure(c(1436248800, 1436249400,
>> >1436251200, 1436254200, 1436258700, 1436259600, 1436261700,
>1436262600,
>> >1436264700, 1436265600, 1436268000, 1436270700, 1436271600,
>1436272200,
>> >NA, 1436248800, 1436249400, 1436249700, 1436250900, 1436253000,
>> >1436254800, 1436256000, 1436263500, 1436264700, 1436265600,
>1436268900,
>> >1436270700, 1436271600, 1436272200, NA), class = c("POSIXct",
>> >"POSIXt"))), .Names = c("start", "akce", "zarizeni", "typ", "prace",
>> >"osoba", "cas", "doba", "endtime"), row.names = c(NA, -30L), class =
>> >"data.frame")
>> >
>> >
>> >
>> >________________________________
>> >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.
>> >
>> >______________________________________________
>> >R-help at r-project.org 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.
>>
>> ______________________________________________
>> R-help at r-project.org 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.
>>



More information about the R-help mailing list