Macrobond R API is available for users with Data+ and Legacy license (the latter without searching and revision history functions). Examples were tested on Macrobond version 1.27, Macrobond API for R version 1.2-8 and R 4.3.0.
See below how to construct ridgeline chart with packages ggplot2 + ggridge. Example is presented on Australia's temperature data from Australian Bureau of Meteorology. Jump to the code.
Images from code for plot 1 (ridges2), plot 2 (ridges_gradient).
With ggplot2 + ggridges packages
library(MacrobondAPI) library(ggplot2) library(ggridges) library(tidyverse) #select series series<-c("auenvo0013") #get dates dates<-getDatesAtStartOfPeriod(FetchOneTimeSeries(series)) #get values values<-getValues(FetchOneTimeSeries(series)) #create data frame for plot 1 (two categories) data<-data.frame(dates, values) %>% mutate(year=as.character(lubridate::year(dates)), #create column with year quarter=as.character(lubridate::quarter(dates))) %>% #create column with quarter mutate(quarter = fct_relevel(quarter, levels = "4", "3", "2", "1")) %>% #to have specific order of data in ggplot2 you need to set levels filter(year %in% c(1871, 2021)) #filter data for specific periods #create data frame for plot 2 (one category) data2<-data.frame(dates, values) %>% mutate(year=as.character(lubridate::year(dates)), #create column with year quarter=as.character(lubridate::quarter(dates))) %>% #create column with quarter mutate(quarter = fct_relevel(quarter, levels = "4", "3", "2", "1")) %>% #to have specific order of data in ggplot2 you need to set levels filter(year %in% c(2021)) #filter data for specific period #plot 1, with transparent colors ggplot(data, aes(x = values, y =quarter, fill=year)) + geom_density_ridges2(alpha = 0.7, #ggridges option scale=1) + scale_fill_manual(values=c("#ffd700", "#cc2d0c")) + #colors scale_x_continuous(breaks=c(-10, -5, 0, 5, 10, 15, 20, 25, 30, 35, 40, 45)) + #set specific ticks on x-axis xlab("high air temperature") + #x-axis label ylab("quarter of year") + #y-axis label ggtitle("Australia, Sydney") + #title theme_minimal() #plot 2, with cold-hot gradient ggplot(data2, aes(x = values, y =quarter, fill=stat(x))) + geom_density_ridges_gradient(scale=1, #ggridges option linetype=0)+ #border lines scale_fill_viridis_c(name = "Temp.", option = "C")+ #colors + legend's title scale_x_continuous(breaks=c(-10, -5, 0, 5, 10, 15, 20, 25, 30, 35, 40, 45)) + #set specific ticks on x-axis xlab("high air temperature") + #x-axis label ylab("quarter of year") + #y-axis label ggtitle("Australia, Sydney 2021") + #title theme_minimal()