Adjusting axis limits in ggplot2.

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Adjusting axis limits in ggplot2.

Rolf Turner

I'm having trouble adjusting axis limits in ggplot2 when the variable
corresponding to that axis is a factor.  I have attached a minimal
reproducible example in the file demo.txt.

The result (see it by sourcing demo.txt and printing ldCiPlot) is fine
except that I would like the y-axis limits to be 0 and 7 rather than
0.5 and 6.5.

I tried adding xlim(0,7) ("x" because I do a coord_flip()) but this
causes the error

> Error: Discrete value supplied to continuous scale

to be thrown.  I have Googled around quite a bit and have not managed to
find anything useful that I can understand.  I'm sure there is a simple
solution, but I can't find it.  Can anyone point me in the right
direction?  Ta.

cheers,

Rolf Turner

--
Honorary Research Fellow
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

______________________________________________
[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.

demo.txt (1K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Adjusting axis limits in ggplot2.

Jeff Newmiller
?scale_x_discrete, in particular the expand argument.

On June 19, 2020 7:07:32 PM PDT, Rolf Turner <[hidden email]> wrote:

>
>I'm having trouble adjusting axis limits in ggplot2 when the variable
>corresponding to that axis is a factor.  I have attached a minimal
>reproducible example in the file demo.txt.
>
>The result (see it by sourcing demo.txt and printing ldCiPlot) is fine
>except that I would like the y-axis limits to be 0 and 7 rather than
>0.5 and 6.5.
>
>I tried adding xlim(0,7) ("x" because I do a coord_flip()) but this
>causes the error
>
>> Error: Discrete value supplied to continuous scale
>
>to be thrown.  I have Googled around quite a bit and have not managed
>to
>find anything useful that I can understand.  I'm sure there is a simple
>solution, but I can't find it.  Can anyone point me in the right
>direction?  Ta.
>
>cheers,
>
>Rolf Turner

--
Sent from my phone. Please excuse my brevity.

______________________________________________
[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: Adjusting axis limits in ggplot2.

Rolf Turner

On 20/06/20 3:57 pm, Jeff Newmiller wrote:

> ?scale_x_discrete, in particular the expand argument.

Thanks Jeff.  Took me a while to get my head around it (I'm slow!!!) but
I eventually got it.

For the record, what I needed to do was set:

ldCiPlot <- ldCiPlot + scale_x_discrete(expand=expansion(add=1))

Thanks again.

cheers,

Rolf

>
> On June 19, 2020 7:07:32 PM PDT, Rolf Turner <[hidden email]> wrote:
>>
>> I'm having trouble adjusting axis limits in ggplot2 when the variable
>> corresponding to that axis is a factor.  I have attached a minimal
>> reproducible example in the file demo.txt.
>>
>> The result (see it by sourcing demo.txt and printing ldCiPlot) is fine
>> except that I would like the y-axis limits to be 0 and 7 rather than
>> 0.5 and 6.5.
>>
>> I tried adding xlim(0,7) ("x" because I do a coord_flip()) but this
>> causes the error
>>
>>> Error: Discrete value supplied to continuous scale
>>
>> to be thrown.  I have Googled around quite a bit and have not managed
>> to
>> find anything useful that I can understand.  I'm sure there is a simple
>> solution, but I can't find it.  Can anyone point me in the right
>> direction?  Ta.
>>
>> cheers,
>>
>> Rolf Turner

______________________________________________
[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.