andrewcparnell / simmr

A stable isotope mixing model in R
https://andrewcparnell.github.io/simmr/
28 stars 8 forks source link

Controlling X-axis ticks in plot(simmr_groups_out,type='boxplot') #9

Closed ChrisHarrod closed 5 years ago

ChrisHarrod commented 7 years ago

Dear Andrew

firstly thanks for the nice, fast mixing model. I have a plotting question, e.g. with this function plot(simmr_groups_out,type='boxplot',group=1,title='simmr output group 1')

I'm probably being really stupid, but is there a quick way to force the boxplots to have a similar format for x axis tick intervals? I have mixing model outputs for 4 groups. For three, the ticks intervals are every 0.25, but for one it's 0.2! obviously, I'd like to get them all in a common format.

Cheers Chris

andrewcparnell commented 7 years ago

Hi Chris,

I'm assuming you're running that command as part of the simmr vignette? And so when you plot group 1, group 2, etc, you want them all to have the same x-axis range?

This isn't currently possible in simmr but I can write you some code which does it?

Andrew

ChrisHarrod commented 7 years ago

Hi Andrew yes - I've blagged the code from the vignette

If you could do that, it would be very, very much appreciated. The manuscript isn't ready yet, but I'd like to look fancy for when we submit it.

Cheers Chris

andrewcparnell commented 7 years ago

Hi Chris,

OK if you run

source('https://raw.githubusercontent.com/andrewcparnell/simmr/master/R/plot.simmr_output.R')
plot(simmr_groups_out,type='boxplot',group=1:4, ggargs = ylim(0,1))

It should now produce a plot of e.g. each group 1 to 4 each with axis limits going from 0 to 1 (or whatever else you specify).

Andrew

ChrisHarrod commented 7 years ago

Hi Andrew Many thanks for your time Did this, but got the following error

Error in scale_fill_viridis(discrete = TRUE) : could not find function "scale_fill_viridis"

Cheers Chris

From: Andrew Parnell [mailto:notifications@github.com] Sent: 22 September 2017 09:25 To: andrewcparnell/simmr simmr@noreply.github.com Cc: Chris Harrod Chris@harrodlab.net; Author author@noreply.github.com Subject: Re: [andrewcparnell/simmr] Controlling X-axis ticks in plot(simmr_groups_out,type='boxplot') (#9)

Hi Chris,

OK if you run

source('https://raw.githubusercontent.com/andrewcparnell/simmr/master/R/plot.simmr_output.R')

plot(simmr_groups_out,type='boxplot',group=1:4, ggargs = ylim(0,1))

It should now produce a plot of e.g. each group 1 to 4 each with axis limits going from 0 to 1 (or whatever else you specify).

Andrew

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/andrewcparnell/simmr/issues/9#issuecomment-331432419, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AJuZNO2gx68It-IzQd9KP-PXU7KPv-7dks5sk6cYgaJpZM4Pc2fc.

andrewcparnell commented 7 years ago

Hi Chris.

Ah. You need some extra package calls before you run the plot command. Likely starting with:

library(MASS)
library(compositions)
library(boot)
library(reshape2)
library(coda)
library(viridis)

will fix it.

Andrew

ChrisHarrod commented 7 years ago

I suspected as much, but am with crappy Internet. Will install them later tonight.

Many thanks Andrew Chris

-------- Original message -------- From: Andrew Parnell notifications@github.com Date: 22/09/2017 14:55 (GMT-03:00) To: andrewcparnell/simmr simmr@noreply.github.com Cc: Chris Harrod Chris@harrodlab.net, Author author@noreply.github.com Subject: Re: [andrewcparnell/simmr] Controlling X-axis ticks in plot(simmr_groups_out,type='boxplot') (#9)

Hi Chris.

Ah. You need some extra package calls before you run the plot command. Likely starting with:

library(MASS) library(compositions) library(boot) library(reshape2) library(coda) library(viridis)

will fix it.

Andrew

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/andrewcparnell/simmr/issues/9#issuecomment-331517524, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AJuZNIaNo0wZPGa92PZwrSNfxx1FqQcHks5sk_R9gaJpZM4Pc2fc.

andrewcparnell commented 7 years ago

Those packages should all have been installed with simmr, so you shouldn't need to install them again.

Andrew

andrewcparnell commented 6 years ago

Hi Chris,

Can you send me a reproducible example?

Andrew


Prof Andrew Parnell, Hamilton Institute, Maynooth University, Ireland

On 5 Sep 2018, at 17:33, ChrisHarrod notifications@github.com<mailto:notifications@github.com> wrote:

Hi Andrew - I finally got back to this and the problem continues...

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHubhttps://github.com/andrewcparnell/simmr/issues/9#issuecomment-418796230, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ADX0ZWD-OgC4xeSJ6poRJ1IJHAhUyZLTks5uX_zRgaJpZM4Pc2fc.

ChrisHarrod commented 6 years ago

Andrew

It’s working now. Not sure what happened, but after a restart, the planets aligned and whammo – it worked ok.

Thanks and apologies for bothering you

C

From: Andrew Parnell notifications@github.com Sent: 05 September 2018 17:21 To: andrewcparnell/simmr simmr@noreply.github.com Cc: Chris Harrod Chris@harrodlab.net; Author author@noreply.github.com Subject: Re: [andrewcparnell/simmr] Controlling X-axis ticks in plot(simmr_groups_out,type='boxplot') (#9)

Hi Chris,

Can you send me a reproducible example?

Andrew


Prof Andrew Parnell, Hamilton Institute, Maynooth University, Ireland

On 5 Sep 2018, at 17:33, ChrisHarrod notifications@github.com<mailto:notifications@github.com<mailto:notifications@github.com%3cmailto:notifications@github.com>> wrote:

Hi Andrew - I finally got back to this and the problem continues...

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHubhttps://github.com/andrewcparnell/simmr/issues/9#issuecomment-418796230, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ADX0ZWD-OgC4xeSJ6poRJ1IJHAhUyZLTks5uX_zRgaJpZM4Pc2fc.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/andrewcparnell/simmr/issues/9#issuecomment-418868045, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AJuZNA-rY-2GkC7tykZVa3DsculPGvnzks5uYDIjgaJpZM4Pc2fc.

andrewcparnell commented 6 years ago

No worries. Always good to hear a success story. They’re rare enough!

Andrew


Prof Andrew Parnell, Hamilton Institute, Maynooth University, Ireland

On 5 Sep 2018, at 21:35, ChrisHarrod notifications@github.com<mailto:notifications@github.com> wrote:

Andrew

It’s working now. Not sure what happened, but after a restart, the planets aligned and whammo – it worked ok.

Thanks and apologies for bothering you

C

From: Andrew Parnell notifications@github.com<mailto:notifications@github.com> Sent: 05 September 2018 17:21 To: andrewcparnell/simmr simmr@noreply.github.com<mailto:simmr@noreply.github.com> Cc: Chris Harrod Chris@harrodlab.net<mailto:Chris@harrodlab.net>; Author author@noreply.github.com<mailto:author@noreply.github.com> Subject: Re: [andrewcparnell/simmr] Controlling X-axis ticks in plot(simmr_groups_out,type='boxplot') (#9)

Hi Chris,

Can you send me a reproducible example?

Andrew


Prof Andrew Parnell, Hamilton Institute, Maynooth University, Ireland

On 5 Sep 2018, at 17:33, ChrisHarrod notifications@github.com<mailto:notifications@github.commailto:notifications@github.com<mailto:notifications@github.com%3cmailto:notifications@github.com<mailto:notifications@github.com>>> wrote:

Hi Andrew - I finally got back to this and the problem continues...

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHubhttps://github.com/andrewcparnell/simmr/issues/9#issuecomment-418796230, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ADX0ZWD-OgC4xeSJ6poRJ1IJHAhUyZLTks5uX_zRgaJpZM4Pc2fc.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/andrewcparnell/simmr/issues/9#issuecomment-418868045, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AJuZNA-rY-2GkC7tykZVa3DsculPGvnzks5uYDIjgaJpZM4Pc2fc.

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHubhttps://github.com/andrewcparnell/simmr/issues/9#issuecomment-418872258, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ADX0Ze-jh7ytjPlNrjC1RXJJLoNvbx_Eks5uYDWAgaJpZM4Pc2fc.

bluepahl commented 4 years ago

Hi Dr. Parnell (and Dr. Harrod) I've used the code: ggargs = ylim(0,1)) to set the y limits (i.e. the y-axis ticks), however, is there a way to set the xlimits in a similar way? I've tried ggargs=(((ylim(10,20)), (xlim(-19,-13))) but it doesn't like that. I've also tried using ggargs twice, but then it says there's multiple arguments for the ggargs function. Thank you for your help, Blue.

andrewcparnell commented 4 years ago

Hi Blue,

Without seeing a reproducible example I'm not sure I can really help you. However, you could try something like:

plot(simmr_out,type='density') + xlim(0, 0.5)

...and it might work.

Andrew

bluepahl commented 4 years ago

Hi Dr. Parnell, Apparently you and Dr. Jackson added xlim and ylim functions into the package to change the axes limits - thank you! Second question: Is there a way to assign different colours to the prey groups in the output plots like the boxplots? I'm looking at 11 different predator species and while most of them have the same 5 prey groups, occasionally one with be different and I'd like to be able to assign it a different colour so as not to confuse a reader into thinking the prey items are the same. Thank you for your help! Blue.

andrewcparnell commented 4 years ago

Hi Blue,

Yes this is possible but it would require you to learn a little bit of ggplot2 and get inside the plot.simmr_output function. In the function you'll see that the fill colour of the boxplots is by source. To change it you'd need create your own variable which represents the colours you want and then colour by this new variable.

I've just put an example of doing this in the vignette in case you want to change it to your needs. It's currently implemented only in the development version but will soon make it on to the official version.

Andrew

ViniciusNeres-Lima commented 2 years ago

Hi Blue,

Without seeing a reproducible example I'm not sure I can really help you. However, you could try something like:

plot(simmr_out,type='density') + xlim(0, 0.5)

...and it might work.

Andrew

Hi, Andrew and Blue,

I used

ggargs= list(ylim(10,20), ylim(-19,-13))

and it worked fine.

Andrew, thanks for the simmr.

Vinicius