Hi Andre ,

If you must stay in quantmod, you can add some cosmetic tweaks manually:

library(quantmod)

chartSeries(portf_xts,
            theme = chartTheme("white"),
            name = "Portfolio Cumulative Return",
            TA = NULL) # remove technical analysis overlays for clean chart

# Add a subtitle manually
mtext("Actives: AAPL, MSFT | Weights: 50%, 50%", side = 3, line = 0.5, cex
= 0.8)

# Rotate x-axis labels manually
axis(1, at = axTicks(1), labels = FALSE)
text(x = axTicks(1),
     y = par("usr")[3] - 0.05,
     srt = 45, adj = 1,
     labels = format(index(portf_xts)[axTicks(1)], "%d %b %y"),
     xpd = TRUE, cex = 0.7)

This works but is clunky — you’re manually redrawing parts of the chart.




On Mon, Nov 10, 2025, 14:44 Andre Luiz Tietbohl Ramos <
[email protected]> wrote:

> Hello,
>
> I'd like to customize the makeChart function output of the quantmod
> library.  Its main objective is threefold:
>
> 1. have x axis labels at 45 degree angle.
> 2. have a title and subtitle
> 3. have labels legends.
>
> I can obtain the desired output via the ggplot code below.  However, the
> chartSeries() function doesn't work. port_cumulative_ret along with the
> other data required are obtained via tiidyquant library.
>
> port_cumulative_ret %>%
>     ## axis data
>     ggplot(aes(x = date, y = cum_ret)) +
>     ## plot configuration
>     theme_gray() +
>     theme(plot.background = element_rect(fill = "gray86")) +
>     geom_line(color = "blue") +
>     theme(axis.text.x = element_text(angle = 50, hjust = 1)) +  ## x axis
> text at 45 degree angle
>     ## graph text, notation and number settings
>     labs(x = 'Data',
>             y = 'Cum Return',
>          title = paste0('Portfolio Cum Return on ', format(as.Date(end),
> format="%m/%d/%Y")),
>          subtitle = paste0("Actives: ", toString(tickers.clean),
> "\nWeights: ",
>                            toString(percent(wts, accuracy = 0.01)))
>          ) +
>     ## axis numbering settings
>     scale_x_date(date_breaks = '2 weeks',
>                  date_labels = '%d %b %y')
>     )
>
> Thanks in advance for any help.
>
> --
> André Luiz T. Ramos, PhD
>
>         [[alternative HTML version deleted]]
>
> _______________________________________________
> [email protected] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only. If you want to post, subscribe first.
> -- Also note that this is not the r-help list where general R questions
> should go.
>

        [[alternative HTML version deleted]]

_______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-finance
-- Subscriber-posting only. If you want to post, subscribe first.
-- Also note that this is not the r-help list where general R questions should 
go.

Reply via email to