Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ggplot aestethics in ts_plot and issue saving plot #6

Open
mpaulasg opened this issue Jul 7, 2022 · 3 comments
Open

ggplot aestethics in ts_plot and issue saving plot #6

mpaulasg opened this issue Jul 7, 2022 · 3 comments
Assignees
Labels

Comments

@mpaulasg
Copy link

mpaulasg commented Jul 7, 2022

Hi Mikko,

Thank you for this package! I'm able to obtain the T-S plot successfully, but I'm now trying to change the size and colour of axis titles, etc, and I'm not able to do this. I've tried adding this change inside ts_plot and outside, but no success. Is this possible?

Another issue is that I'm trying to save the plot using ggsave, but instead I obtained an empty plot. I can save other plots using the exact same code, so I guess it should be an issue with this function. See an example below.

Thank you in advance!
Paula

library(PlotSvalbard)
library(here)

#Setting some graphical details

color_cross <- c("Inshore" = "#6C809A", "Midshelf" = "#FAAA8D", "Offshore" = "#98473E")

#Create data

CTD <- data.frame(Habitat = c("Inshore", "Inshore", "Inshore", "Midshelf", "Midshelf","Midshelf", "Offshore",
"Offshore","Offshore"),
Depth = c(1, 2, 3,1, 2, 3,1, 2, 3 ),
Temp = c (23, 22.5, 21, 22, 22, 24.5, 24, 25, 24.5),
Sal = c(35.5, 35.8, 35, 34.5, 34.6, 34.6, 34, 34.2, 34))

#Plot TS

ts <- ts_plot( CTD,
temp_col = "Temp",
sal_col = "Sal",
WM = NULL,
color_wmpoly = NULL,
xlim = c(33,36),
ylim = c(20,26),
color = "Habitat",
zoom = TRUE,
nlevels = 1,
color_isopyc = "grey90",
symbol_shape = 16,
symbol_size = 3,
symbol_alpha = 0.6,
color_scale = color_cross,
color_var_name = NULL,
margin_distr = TRUE, #this one shows Kernel density
margin_width = 0.15,
margin_height = 0.2,
plot_data = TRUE,
base_size = 10

)

ggsave(ts, file=here::here("graphs", "ts_cross.png"),
height = 22, width = 25, unit = "cm" ) #Doesn't work

@MikkoVihtakari
Copy link
Owner

MikkoVihtakari commented Jul 10, 2022

Hi Paula,

Thanks for the bug-report. Try rather ggOceanPlots. It is more updated (and development of PlotSvalbard has ended). It seems that the marginal plot code in the ts_plot() function is outdated. It plots to grid instead of returning a grid (or ggplot2) object. I'll update the code when I'll have time (I have solved the issue in more recent scripts which I have not shared here). In the meanwhile you can either not use marginal distributions (set margin_distr to FALSE) or by-pass the problem by printing inside the png() device. The latter option does not let you control the axes labels using ggplot2 functions (because ts_plot() does not return a ggplot2 object when margin_distr = TRUE; this is a clear design issue and a bug that can be fixed).

library(ggOceanPlots)
library(ggplot2)

#Setting some graphical details

color_cross <- c("Inshore" = "#6C809A", "Midshelf" = "#FAAA8D", "Offshore" = "#98473E")

#Create data

CTD <- data.frame(Habitat = c("Inshore", "Inshore", "Inshore", "Midshelf", "Midshelf","Midshelf", "Offshore",
                              "Offshore","Offshore"),
                  Depth = c(1, 2, 3,1, 2, 3,1, 2, 3 ),
                  Temp = c (23, 22.5, 21, 22, 22, 24.5, 24, 25, 24.5),
                  Sal = c(35.5, 35.8, 35, 34.5, 34.6, 34.6, 34, 34.2, 34))

png("test.png", height = 22, width = 25, unit = "cm", res = 300)
ts_plot(CTD,
        temp_col = "Temp",
        sal_col = "Sal",
        WM = NULL,
        color_wmpoly = NULL,
        xlim = c(33,36),
        ylim = c(20,26),
        color = "Habitat",
        zoom = TRUE,
        nlevels = 1,
        color_isopyc = "grey90",
        symbol_shape = 16,
        symbol_size = 3,
        symbol_alpha = 0.6,
        color_scale = color_cross,
        color_var_name = NULL,
        margin_distr = TRUE, #this one shows Kernel density
        margin_width = 0.15,
        margin_height = 0.2,
        plot_data = TRUE,
        base_size = 10
) 
dev.off()

test

ts <- ts_plot(CTD,
        temp_col = "Temp",
        sal_col = "Sal",
        WM = NULL,
        color_wmpoly = NULL,
        xlim = c(33,36),
        ylim = c(20,26),
        color = "Habitat",
        zoom = TRUE,
        nlevels = 1,
        color_isopyc = "grey90",
        symbol_shape = 16,
        symbol_size = 3,
        symbol_alpha = 0.6,
        color_scale = color_cross,
        color_var_name = NULL,
        margin_distr = FALSE, #this one shows Kernel density
        margin_width = 0.15,
        margin_height = 0.2,
        plot_data = TRUE,
        base_size = 10) +
  ggplot2::theme(axis.title = element_text(size = 20, color = "blue"))

ggsave(ts, file = "test2.png",
       height = 22, width = 25, unit = "cm" ) # Works

test2

@MikkoVihtakari MikkoVihtakari self-assigned this Jul 10, 2022
@mpaulasg
Copy link
Author

Hi Mikko,

So sorry for my late reply!

Thank you, I'm now using ggOceanPlots. I want to keep the Kernel density graphs so unfortunately, I can't set the marginal distributions off. However, I just changed the letter sizes with base_size and that's good enough for my figures.

Thanks again!

Paula

@MikkoVihtakari
Copy link
Owner

Thanks. Let's just keep this open as a reminder that I'll need to look into this one day when I have time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants