Skip to content

Commit

Permalink
add dataset title to BAR plot
Browse files Browse the repository at this point in the history
  • Loading branch information
RayStick committed Jan 6, 2025
1 parent 14d4463 commit 032bb1b
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 12 deletions.
3 changes: 2 additions & 1 deletion R/metadata_map.R
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ metadata_map <- function(
empty_count_df <- empty_count(dataset)

## Use 'empty_plot.R' to create bar plot then save it
barplot_html <- empty_plot(empty_count_df, n_tables)
bar_title <- paste0("\n'", dataset_name, "' contains ", n_tables, " table(s)")
barplot_html <- empty_plot(empty_count_df, bar_title)
original_wd <- getwd()
setwd(output_dir) # saveWidget has a bug with paths & saving
base_fname <- paste0(
Expand Down
6 changes: 3 additions & 3 deletions R/plotting.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
#' This function is called within the metadata_map function. \cr \cr
#' It plots \cr \cr
#' @param dataframe Dataframe to plot. Output of empty_count.R function.
#' @param n_tables The number of table names in this dataframe.
#' @param bar_title Title for the plot.
#' @return A plotly object
#' @keywords internal
#' @importFrom plotly plot_ly layout

empty_plot <- function(dataframe, n_tables) {
empty_plot <- function(dataframe, bar_title) {
barplot_html <- plot_ly(dataframe,
x = ~Table,
y = ~N_Variables,
Expand All @@ -22,7 +22,7 @@ empty_plot <- function(dataframe, n_tables) {
) %>%
layout(
barmode = "stack",
title = paste0("\n", "Dataset contains ", n_tables, " table(s)"),
title = bar_title,
xaxis = list(title = "Table"),
yaxis = list(title = "Variable Count"),
legend = list(title = list(text = "Empty Description"))
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ Press 'Esc' key to finish here, or press any other key to continue with mapping

Stopping here just gets you the summary plot, which is saved to your project directory. All outputs from this `metadata_map` function are saved to your project directory. You can change the save location by adjusting the `output_dir` argument.

<img src="https://raw.githubusercontent.com/aim-rsf/mapmetadata/main/inst/outputs/BAR_360_NationalCommunityChildHealthDatabase(NCCHD)_2024-12-19-18-07-22.png" alt="example bar plot showing number of variables for each table alongside counts of whether variables have missing descriptions">
<img src="https://raw.githubusercontent.com/aim-rsf/mapmetadata/main/inst/outputs/BAR_360_NationalCommunityChildHealthDatabase(NCCHD)_2024-12-19-14-11-55.png" alt="example bar plot showing number of variables for each table alongside counts of whether variables have missing descriptions">

If you continue, the function will ask you to pick a table in the dataset. In demo mode, the function processes only the first 20 variables from the selected table. Follow the on-screen instructions, and categorise variables into research domains, using the Plot tab as your reference. The demo will simplify domains for ease of use; in a real scenario, you can define more specific domains. For more tips on these mapping steps, see the [mapmetadata tutorial](https://aim-rsf.github.io/mapmetadata/articles/mapmetadata.html) page on the package website.

Expand Down
2 changes: 1 addition & 1 deletion codemeta.json
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@
},
"SystemRequirements": null
},
"fileSize": "6141.312KB",
"fileSize": "6164.024KB",
"citation": [
{
"@type": "SoftwareSourceCode",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1953,9 +1953,9 @@
</head>
<body style="background-color: white;">
<div id="htmlwidget_container">
<div class="plotly html-widget html-fill-item" id="htmlwidget-946d0684e4aa2bfc590b" style="width:100%;height:400px;"></div>
<div class="plotly html-widget html-fill-item" id="htmlwidget-ddcafaff89c2b557e44a" style="width:100%;height:400px;"></div>
</div>
<script type="application/json" data-for="htmlwidget-946d0684e4aa2bfc590b">{"x":{"visdat":{"9226cfc2aa6":["function () ","plotlyVisDat"]},"cur_data":"9226cfc2aa6","attrs":{"9226cfc2aa6":{"x":{},"y":{},"text":{},"textposition":"inside","texttemplate":"%{text}","textfont":{"color":"black","size":10},"color":{},"colors":["grey","darkturquoise"],"alpha_stroke":1,"sizes":[10,100],"spans":[1,20],"type":"bar"}},"layout":{"margin":{"b":40,"l":60,"t":25,"r":10},"barmode":"stack","title":"<br />Dataset contains 13 table(s)","xaxis":{"domain":[0,1],"automargin":true,"title":"Table","type":"category","categoryorder":"array","categoryarray":["BLOOD_TEST","BREAST_FEEDING","CHE_HEALTHYCHILDWALESPROGRAMME","CHILD","CHILD_BIRTHS","CHILD_MEASUREMENT_PROGRAM","CHILD_TRUST","EXAM","IMM","PATH_BLOOD_TESTS","PATH_SPCM_DETAIL","REFR_IMM_VAC","SIG_COND"]},"yaxis":{"domain":[0,1],"automargin":true,"title":"Variable Count"},"legend":{"title":{"text":"Empty Description"}},"hovermode":"closest","showlegend":true},"source":"A","config":{"modeBarButtonsToAdd":["hoverclosest","hovercompare"],"showSendToCloud":false},"data":[{"x":["BLOOD_TEST","BREAST_FEEDING","CHE_HEALTHYCHILDWALESPROGRAMME","CHILD","CHILD_BIRTHS","CHILD_MEASUREMENT_PROGRAM","CHILD_TRUST","EXAM","IMM","PATH_BLOOD_TESTS","PATH_SPCM_DETAIL","REFR_IMM_VAC","SIG_COND"],"y":[6,6,8,35,36,30,59,31,10,13,9,5,8],"text":[6,6,8,35,36,30,59,31,10,13,9,5,8],"textposition":["inside","inside","inside","inside","inside","inside","inside","inside","inside","inside","inside","inside","inside"],"texttemplate":["%{text}","%{text}","%{text}","%{text}","%{text}","%{text}","%{text}","%{text}","%{text}","%{text}","%{text}","%{text}","%{text}"],"textfont":{"color":"black","size":10},"type":"bar","name":"No","marker":{"color":"rgba(190,190,190,1)","line":{"color":"rgba(190,190,190,1)"}},"error_y":{"color":"rgba(190,190,190,1)"},"error_x":{"color":"rgba(190,190,190,1)"},"xaxis":"x","yaxis":"y","frame":null},{"x":["BLOOD_TEST","BREAST_FEEDING","CHE_HEALTHYCHILDWALESPROGRAMME","CHILD","CHILD_BIRTHS","CHILD_MEASUREMENT_PROGRAM","CHILD_TRUST","EXAM","IMM","PATH_BLOOD_TESTS","PATH_SPCM_DETAIL","REFR_IMM_VAC","SIG_COND"],"y":[2,2,32,0,0,0,5,0,1,7,13,0,0],"text":[2,2,32,0,0,0,5,0,1,7,13,0,0],"textposition":["inside","inside","inside","inside","inside","inside","inside","inside","inside","inside","inside","inside","inside"],"texttemplate":["%{text}","%{text}","%{text}","%{text}","%{text}","%{text}","%{text}","%{text}","%{text}","%{text}","%{text}","%{text}","%{text}"],"textfont":{"color":"black","size":10},"type":"bar","name":"Yes","marker":{"color":"rgba(0,206,209,1)","line":{"color":"rgba(0,206,209,1)"}},"error_y":{"color":"rgba(0,206,209,1)"},"error_x":{"color":"rgba(0,206,209,1)"},"xaxis":"x","yaxis":"y","frame":null}],"highlight":{"on":"plotly_click","persistent":false,"dynamic":false,"selectize":false,"opacityDim":0.20000000000000001,"selected":{"opacity":1},"debounce":0},"shinyEvents":["plotly_hover","plotly_click","plotly_selected","plotly_relayout","plotly_brushed","plotly_brushing","plotly_clickannotation","plotly_doubleclick","plotly_deselect","plotly_afterplot","plotly_sunburstclick"],"base_url":"https://plot.ly"},"evals":[],"jsHooks":[]}</script>
<script type="application/htmlwidget-sizing" data-for="htmlwidget-946d0684e4aa2bfc590b">{"viewer":{"width":"100%","height":400,"padding":0,"fill":true},"browser":{"width":"100%","height":400,"padding":0,"fill":true}}</script>
<script type="application/json" data-for="htmlwidget-ddcafaff89c2b557e44a">{"x":{"visdat":{"387fa4da0ff":["function () ","plotlyVisDat"]},"cur_data":"387fa4da0ff","attrs":{"387fa4da0ff":{"x":{},"y":{},"text":{},"textposition":"inside","texttemplate":"%{text}","textfont":{"color":"black","size":10},"color":{},"colors":["grey","darkturquoise"],"alpha_stroke":1,"sizes":[10,100],"spans":[1,20],"type":"bar"}},"layout":{"margin":{"b":40,"l":60,"t":25,"r":10},"barmode":"stack","title":"<br />'360_NationalCommunityChildHealthDatabase(NCCHD)' contains 13 table(s)","xaxis":{"domain":[0,1],"automargin":true,"title":"Table","type":"category","categoryorder":"array","categoryarray":["BLOOD_TEST","BREAST_FEEDING","CHE_HEALTHYCHILDWALESPROGRAMME","CHILD","CHILD_BIRTHS","CHILD_MEASUREMENT_PROGRAM","CHILD_TRUST","EXAM","IMM","PATH_BLOOD_TESTS","PATH_SPCM_DETAIL","REFR_IMM_VAC","SIG_COND"]},"yaxis":{"domain":[0,1],"automargin":true,"title":"Variable Count"},"legend":{"title":{"text":"Empty Description"}},"hovermode":"closest","showlegend":true},"source":"A","config":{"modeBarButtonsToAdd":["hoverclosest","hovercompare"],"showSendToCloud":false},"data":[{"x":["BLOOD_TEST","BREAST_FEEDING","CHE_HEALTHYCHILDWALESPROGRAMME","CHILD","CHILD_BIRTHS","CHILD_MEASUREMENT_PROGRAM","CHILD_TRUST","EXAM","IMM","PATH_BLOOD_TESTS","PATH_SPCM_DETAIL","REFR_IMM_VAC","SIG_COND"],"y":[6,6,8,35,36,30,59,31,10,13,9,5,8],"text":[6,6,8,35,36,30,59,31,10,13,9,5,8],"textposition":["inside","inside","inside","inside","inside","inside","inside","inside","inside","inside","inside","inside","inside"],"texttemplate":["%{text}","%{text}","%{text}","%{text}","%{text}","%{text}","%{text}","%{text}","%{text}","%{text}","%{text}","%{text}","%{text}"],"textfont":{"color":"black","size":10},"type":"bar","name":"No","marker":{"color":"rgba(190,190,190,1)","line":{"color":"rgba(190,190,190,1)"}},"error_y":{"color":"rgba(190,190,190,1)"},"error_x":{"color":"rgba(190,190,190,1)"},"xaxis":"x","yaxis":"y","frame":null},{"x":["BLOOD_TEST","BREAST_FEEDING","CHE_HEALTHYCHILDWALESPROGRAMME","CHILD","CHILD_BIRTHS","CHILD_MEASUREMENT_PROGRAM","CHILD_TRUST","EXAM","IMM","PATH_BLOOD_TESTS","PATH_SPCM_DETAIL","REFR_IMM_VAC","SIG_COND"],"y":[2,2,32,0,0,0,5,0,1,7,13,0,0],"text":[2,2,32,0,0,0,5,0,1,7,13,0,0],"textposition":["inside","inside","inside","inside","inside","inside","inside","inside","inside","inside","inside","inside","inside"],"texttemplate":["%{text}","%{text}","%{text}","%{text}","%{text}","%{text}","%{text}","%{text}","%{text}","%{text}","%{text}","%{text}","%{text}"],"textfont":{"color":"black","size":10},"type":"bar","name":"Yes","marker":{"color":"rgba(0,206,209,1)","line":{"color":"rgba(0,206,209,1)"}},"error_y":{"color":"rgba(0,206,209,1)"},"error_x":{"color":"rgba(0,206,209,1)"},"xaxis":"x","yaxis":"y","frame":null}],"highlight":{"on":"plotly_click","persistent":false,"dynamic":false,"selectize":false,"opacityDim":0.20000000000000001,"selected":{"opacity":1},"debounce":0},"shinyEvents":["plotly_hover","plotly_click","plotly_selected","plotly_relayout","plotly_brushed","plotly_brushing","plotly_clickannotation","plotly_doubleclick","plotly_deselect","plotly_afterplot","plotly_sunburstclick"],"base_url":"https://plot.ly"},"evals":[],"jsHooks":[]}</script>
<script type="application/htmlwidget-sizing" data-for="htmlwidget-ddcafaff89c2b557e44a">{"viewer":{"width":"100%","height":400,"padding":0,"fill":true},"browser":{"width":"100%","height":400,"padding":0,"fill":true}}</script>
</body>
</html>
4 changes: 2 additions & 2 deletions man/empty_plot.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vignettes/mapmetadata.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ For installation, set-up and basic usage refer to the package [README.md](https:

# Preparing for mapping

<img src="https://raw.githubusercontent.com/aim-rsf/mapmetadata/main/inst/outputs/BAR_360_NationalCommunityChildHealthDatabase(NCCHD)_2024-12-19-18-07-22.png" alt="example bar plot showing number of variables for each table alongside counts of whether variables have missing descriptions"/>
<img src="https://raw.githubusercontent.com/aim-rsf/mapmetadata/main/inst/outputs/BAR_360_NationalCommunityChildHealthDatabase(NCCHD)_2024-12-19-14-11-55.png" alt="example bar plot showing number of variables for each table alongside counts of whether variables have missing descriptions"/>

This bar plot is produced automatically when you run the `metadata_map` function with the demo metadata file, which contains metadata about the **National Community Child Health Database (NCCHD).**

Expand Down

0 comments on commit 032bb1b

Please sign in to comment.