Problem with ggplot2 and geom_segment

68 views
Skip to first unread message

Joe Hightower

unread,
Nov 13, 2014, 6:24:19 PM11/13/14
to ggp...@googlegroups.com
Other recipients:
I have created a series of plots used in Shiny, that displays a curve, then adds a pair of lines to show x and y axis intercepts.  This works great.  The lines are red and dashed. I am trying to add a second set of lines showing a different x and y i
I have created a series of plots used in Shiny, that displays a curve, then adds a pair of lines to show x and y axis intercepts.  This works great.  The lines are red and dashed.

I am trying to add a second set of lines showing a different x and y intercept.  These are supposed to be green and solid.

When I add the second set of lines, things get screwed up.  The second set becomes red and solid, the first set becomes green and dashed. 

Any ideas on what is happening?

    qplot(y()$TrueNC,y()$AOQ,data=y(),
          ylab="Average Outgoing Quality",
          xlab="Probability of Nonconformance",
          main="Average Outgoing Quality",
          xlim=c(0.0,1.0),
          ylim=c(initLimit(),plotYLimit()),
          geom="line"
    )+geom_segment(
                   aes(
                      x = probvec2()[2]+probvec2()[4],
                      y = 0,
                      xend = probvec2()[2]+probvec2()[4],
                      yend = round(max(y()$AOQ),4)+0.01,
                      colour="red"),
                      linetype=2
    )+geom_segment(
                  aes(
                    x = 0,
                    y = approx(y()$TrueNC,y()$AOQ,xout=probvec2()[2]+probvec2()[4],method="linear")$y,
                    xend = probvec2()[2]+probvec2()[4]+0.03,
                    yend = approx(y()$TrueNC,y()$AOQ,xout=probvec2()[2]+probvec2()[4],method="linear")$y,
                    colour="red"),
                    linetype=2
    )+geom_segment(
                  aes(
                    x = approx(y()$AOQ,y()$TrueNC,xout=input$ecr_t,method="linear")$y,
                    y = 0,
                    xend = approx(y()$AOQ,y()$TrueNC,xout=input$ecr_t,method="linear")$y,
                    yend = round(max(y()$AOQ),4)+0.01,
                    colour="green"),
                    linetype=1
    )+geom_segment(
                  aes(
                    x = 0,
                    y = approx(y()$TrueNC,y()$AOQ,xout=probvec2()[2]+probvec2()[4],method="linear")$y,
                    xend = approx(y()$AOQ,y()$TrueNC,xout=input$ecr_t,method="linear")$y+0.03,
                    yend = approx(y()$TrueNC,y()$AOQ,xout=probvec2()[2]+probvec2()[4],method="linear")$y,
                    colour="green"),
                    linetype=1
    )+theme(legend.position = "none")
  })

Dennis Murphy

unread,
Nov 13, 2014, 9:56:04 PM11/13/14
to Joe Hightower, ggplot2
Hi:

Do you understand the difference between mapping and setting
aesthetics in ggplot2? If you want the colors of the segments to be
red and green, _set_ them to those specific values *outside* of aes(),
not inside. Ditto for linetype. aes() is for _mapping_ plot aesthetics
to variables.

Dennis
> --
> --
> You received this message because you are subscribed to the ggplot2 mailing
> list.
> Please provide a reproducible example:
> https://github.com/hadley/devtools/wiki/Reproducibility
>
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2
>
> ---
> You received this message because you are subscribed to the Google Groups
> "ggplot2" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ggplot2+u...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Joe Hightower

unread,
Nov 14, 2014, 2:11:32 PM11/14/14
to ggp...@googlegroups.com, luvmyt...@gmail.com
Outstanding!!!!!  That is just what I needed.  And the answer is that I did not understand the difference.
Reply all
Reply to author
Forward
0 new messages