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

add_indicator_native_range_year function #64

Open
3 tasks done
SanderDevisscher opened this issue Jun 30, 2020 · 11 comments · Fixed by #65
Open
3 tasks done

add_indicator_native_range_year function #64

SanderDevisscher opened this issue Jun 30, 2020 · 11 comments · Fixed by #65
Assignees

Comments

@SanderDevisscher
Copy link
Contributor

SanderDevisscher commented Jun 30, 2020

As suggested by @eadriaensen at issue #145 from reporting-rshiny-grofwildjacht I'll try to add the indicator_native_range_year function to the package.

  • copy script from zip provided by @eadriaensen in comment 651739495
  • test script in trias environment
  • add relative/absolute variable

changes will be made in the add_indicator_native_range_year - branch

@SanderDevisscher
Copy link
Contributor Author

SanderDevisscher commented Jul 6, 2020

@damianooldoni the function uses the data.table, plotly & inbotheme packages should I include these in the description file ?

@SanderDevisscher
Copy link
Contributor Author

@eadriaensen were does the "yearToTitleString" - function originate from ? Did you make it for the app ? or is it part of a package ?

@eadriaensen
Copy link

eadriaensen commented Jul 6, 2020

Yes, this is made for the app:

#' Transform numeric vector with years ready to be in title
#' 
#' @param year numeric, vector of length 1 or 2
#' @param brackets logical, should the output string with years be wrapped in brackets? Defaults to TRUE 
#' @return string Numbers of the vector are separated by 'tot' in the string, 
#' brackets are put around (\code{brackets = TRUE}). If length of vector is only one, or if both elements
#' of the vector are the same, a string with the year between brackets is returned. 
#' 
#' @author Eva Adriaensen
#' @export
yearToTitleString <- function(year, brackets = TRUE) {
  
  if (!is.numeric(year) | any(is.na(year))) {
    stop("Argument is niet aanvaard.")
  }
  
	if (length(year) == 2) {
    ifelse(year[1] != year[2],
        if (brackets) paste0("(", year[1], " tot ", year[2], ")") else paste0(year[1], " tot ", year[2]),
        if (brackets) paste0("(", year[1], ")") else paste0(year[1])
    )
	} else if (length(year) == 1) {
    if (brackets) paste0("(", year[1], ")") else paste0(year[1]) 
	} else {
    stop("Kan periode niet formatteren.")
  }
}

It is part of the reporting-grofwild package

@SanderDevisscher
Copy link
Contributor Author

How can I use it in the trias package ?

@eadriaensen
Copy link

eadriaensen commented Jul 6, 2020

One way would be to include it as an (exported) function of the trias package itself. I.e. just copy pasting the above function.
Alternatively, you could use it from the reporting-grofwild package, but this would mean that trias will always depend on reporting-grofwild, which is not an ideal situation.

The easiest solution would be to not include this function in trias and to exclude the concerning line from the piece of code that I shared. I.e. do not generate the plot with a title. It is kind of redundant since the years are on the x-axis anyway and the big chunks of text that serve as a title can be generated within shiny based on the data.

Screenshot_exoten_title

@eadriaensen
Copy link

So excluding this line

  title <- yearToTitleString(year = c(jaartallen[1], tail(jaartallen, 1)), brackets = FALSE)

and

removing title = title, from the layout specification of the plot:

  # Create plot
  pl <- plot_ly(data = summaryData, x = ~first_observed, y = ~value, color = ~locatie,
          colors = colors, type = "bar",  width = width, height = height) %>%
      layout(title = title,
          xaxis = list(title = "Jaar"), 
          yaxis = list(title = "Aantal", tickformat = ",d"),
          margin = list(b = 80, t = 100), 
          barmode = ifelse(nlevels(summaryData$first_observed) == 1, "group", "stack"),
          annotations = list(x = levels(summaryData$first_observed), 
              y = totalCount, 
              text = paste(ifelse(nlevels(summaryData$first_observed) == 1, "totaal:", ""), ifelse(totalCount > 0, totalCount, "")),
              xanchor = 'center', yanchor = 'bottom',
              showarrow = FALSE),
          showlegend = TRUE)  

@SanderDevisscher
Copy link
Contributor Author

Thanks I'll remove the title portion of the graph as well as the colors as to not make trias dependant on INBOtheme

SanderDevisscher added a commit that referenced this issue Jul 7, 2020
#64
this should enable setting the axis labels in english & dutch (default english)
SanderDevisscher added a commit that referenced this issue Jul 7, 2020
SanderDevisscher added a commit that referenced this issue Jul 7, 2020
@SanderDevisscher
Copy link
Contributor Author

@damianooldoni I think I finished the conversion. But I can't seem to find the "native_continent" value in the data. This is needed for testing on a higher level of geography.

@damianooldoni
Copy link
Collaborator

Hi @SanderDevisscher. I think the column you are searching for is called native_range.

@mvarewyck
Copy link
Collaborator

Could the function argument for data be changed from data to df for consistency with the other trias functions?
This will facilitate calling the trias functions in alien-species-portal

[Note: I don't have permission to do a PR]

damianooldoni added a commit that referenced this issue Mar 27, 2023
@damianooldoni damianooldoni reopened this Mar 27, 2023
@damianooldoni
Copy link
Collaborator

Thanks @mvarewyck! I am solving it just now. I noticed this strange behavior as well: #105. I will fix this as well. I had to pay more attention while reviewing the PR of Sander in 2020 😢

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

Successfully merging a pull request may close this issue.

4 participants