0

With mschart, one create charts in R and export them in ppt.

There are different options in mschart_theme for styling.

For axis_text_x, we can use the function fp_text from the package officer.

Now my question is: is it possible to remove completely axis_text_x ?

I try to set the font size to 0, and it doesn't work. One dirty way is to set the color to "white".

Thank to neuron's comment, I investigated with this example:

library(mschart)
chart_01 <- ms_barchart(
  data = browser_data, x = "browser",
  y = "value", group = "serie"
)
chart_01 <- chart_settings(
  x = chart_01, dir = "vertical",
  grouping = "clustered", gap_width = 50
)
chart_01 <- chart_ax_x(
  x = chart_01, cross_between = "between",
  major_tick_mark = "out"
)
chart_01 <- chart_ax_y(
  x = chart_01, cross_between = "midCat",
  major_tick_mark = "in"
)

Then I used dput:

dput(chart_01)

with the following code:

structure(list(data = structure(list(browser = c("Chrome", "IE", 
"Firefox", "Safari", "Opera", "Android", "Chrome", "IE", "Firefox", 
"Safari", "Opera", "Android", "Chrome", "IE", "Firefox", "Safari", 
"Opera", "Android"), serie = c("serie1", "serie1", "serie1", 
"serie1", "serie1", "serie1", "serie2", "serie2", "serie2", "serie2", 
"serie2", "serie2", "serie3", "serie3", "serie3", "serie3", "serie3", 
"serie3"), value = 1:18), out.attrs = list(dim = c(browser = 6L, 
serie = 3L), dimnames = list(browser = c("browser=Chrome", "browser=IE", 
"browser=Firefox", "browser=Safari", "browser=Opera", "browser=Android"
), serie = c("serie=serie1", "serie=serie2", "serie=serie3"))), row.names = c(NA, 
-18L), class = "data.frame"), x = "browser", y = "value", group = "serie", 
    label_cols = NULL, theme = structure(list(main_title = structure(list(
        font.size = 20, bold = TRUE, italic = FALSE, underlined = FALSE, 
        color = "black", font.family = "Arial", cs.family = "Arial", 
        eastasia.family = "Arial", hansi.family = "Arial", vertical.align = "baseline", 
        shading.color = "transparent"), class = "fp_text"), legend_text = structure(list(
        font.size = 14, bold = FALSE, italic = FALSE, underlined = FALSE, 
        color = "black", font.family = "Arial", cs.family = "Arial", 
        eastasia.family = "Arial", hansi.family = "Arial", vertical.align = "baseline", 
        shading.color = "transparent"), class = "fp_text"), axis_title_x = structure(list(
        font.size = 16, bold = TRUE, italic = FALSE, underlined = FALSE, 
        color = "black", font.family = "Arial", cs.family = "Arial", 
        eastasia.family = "Arial", hansi.family = "Arial", vertical.align = "baseline", 
        shading.color = "transparent"), class = "fp_text"), axis_title_y = structure(list(
        font.size = 16, bold = TRUE, italic = FALSE, underlined = FALSE, 
        color = "black", font.family = "Arial", cs.family = "Arial", 
        eastasia.family = "Arial", hansi.family = "Arial", vertical.align = "baseline", 
        shading.color = "transparent"), class = "fp_text"), title_rot = 0, 
        title_x_rot = 0, title_y_rot = 270, axis_text_x = structure(list(
            font.size = 10, bold = FALSE, italic = FALSE, underlined = FALSE, 
            color = "black", font.family = "Arial", cs.family = "Arial", 
            eastasia.family = "Arial", hansi.family = "Arial", 
            vertical.align = "baseline", shading.color = "transparent"), class = "fp_text"), 
        axis_text_y = structure(list(font.size = 10, bold = FALSE, 
            italic = FALSE, underlined = FALSE, color = "black", 
            font.family = "Arial", cs.family = "Arial", eastasia.family = "Arial", 
            hansi.family = "Arial", vertical.align = "baseline", 
            shading.color = "transparent"), class = "fp_text"), 
        axis_ticks_x = structure(list(width = 1, color = "#99999999", 
            style = "solid"), class = "fp_border"), axis_ticks_y = structure(list(
            width = 1, color = "#99999999", style = "solid"), class = "fp_border"), 
        grid_major_line_x = structure(list(width = 1, color = "#99999999", 
            style = "dashed"), class = "fp_border"), grid_major_line_y = structure(list(
            width = 1, color = "#99999999", style = "dashed"), class = "fp_border"), 
        grid_minor_line_x = structure(list(width = 0, color = "black", 
            style = "solid"), class = "fp_border"), grid_minor_line_y = structure(list(
            width = 0, color = "black", style = "solid"), class = "fp_border"), 
        legend_position = "b"), class = "mschart_theme"), options = structure(list(
        vary_colors = FALSE, gap_width = 150, dir = "vertical", 
        grouping = "clustered", overlap = 0), class = "barchart_options"), 
    x_axis = structure(list(orientation = "minMax", axis_position = "b", 
        crosses = "autoZero", cross_between = "between", delete = FALSE, 
        num_fmt = "General", major_tick_mark = "cross", minor_tick_mark = "none", 
        tick_label_pos = "nextTo", rotation = 0, limit_min = NULL, 
        limit_max = NULL, position = NULL), class = "axis_options"), 
    y_axis = structure(list(orientation = "minMax", axis_position = "l", 
        crosses = "autoZero", cross_between = "between", delete = FALSE, 
        num_fmt = "General", major_tick_mark = "cross", minor_tick_mark = "none", 
        tick_label_pos = "nextTo", rotation = 0, limit_min = NULL, 
        limit_max = NULL, position = NULL), class = "axis_options"), 
    axis_tag = list(x = "c:catAx", y = "c:valAx"), fmt_names = list(
        x = c("Chrome", "IE", "Firefox", "Safari", "Opera", "Android", 
        "Chrome", "IE", "Firefox", "Safari", "Opera", "Android", 
        "Chrome", "IE", "Firefox", "Safari", "Opera", "Android"
        ), y = 1:18), labels = list(title = NULL, x = "browser", 
        y = "value"), label_settings = structure(list(num_fmt = "General", 
        position = "ctr", show_legend_key = FALSE, show_val = FALSE, 
        show_cat_name = FALSE, show_serie_name = FALSE, show_percent = FALSE, 
        separator = ", "), class = "labels_options"), data_series = structure(list(
        browser = c("Android", "Chrome", "Firefox", "IE", "Opera", 
        "Safari"), serie1 = c(6L, 1L, 3L, 2L, 5L, 4L), serie2 = c(12L, 
        7L, 9L, 8L, 11L, 10L), serie3 = c(18L, 13L, 15L, 14L, 
        17L, 16L)), row.names = c(NA, -6L), class = "data.frame"), 
    series_settings = list(fill = c(serie1 = "#4477AA", serie2 = "#DDCC77", 
    serie3 = "#CC6677"), colour = c(serie1 = "#4477AA", serie2 = "#DDCC77", 
    serie3 = "#CC6677"), symbol = c(serie1 = "circle", serie2 = "circle", 
    serie3 = "circle"), line_style = c(serie1 = "solid", serie2 = "solid", 
    serie3 = "solid"), size = c(serie1 = 12, serie2 = 12, serie3 = 12
    ), line_width = c(serie1 = 2, serie2 = 2, serie3 = 2), labels_fp = list(
        serie1 = structure(list(font.size = 0, bold = FALSE, 
            italic = FALSE, underlined = FALSE, color = "black", 
            font.family = "Arial", cs.family = "Arial", eastasia.family = "Arial", 
            hansi.family = "Arial", vertical.align = "baseline", 
            shading.color = "transparent"), class = "fp_text"), 
        serie2 = structure(list(font.size = 0, bold = FALSE, 
            italic = FALSE, underlined = FALSE, color = "black", 
            font.family = "Arial", cs.family = "Arial", eastasia.family = "Arial", 
            hansi.family = "Arial", vertical.align = "baseline", 
            shading.color = "transparent"), class = "fp_text"), 
        serie3 = structure(list(font.size = 0, bold = FALSE, 
            italic = FALSE, underlined = FALSE, color = "black", 
            font.family = "Arial", cs.family = "Arial", eastasia.family = "Arial", 
            hansi.family = "Arial", vertical.align = "baseline", 
            shading.color = "transparent"), class = "fp_text")), 
        smooth = c(serie1 = 1, serie2 = 1, serie3 = 1))), class = c("ms_barchart", 
"ms_chart"))

We can see that in x_axis, there is an item delete=FALSE if we could change it to delete=T but I don't know how to do it directly.

I also find a function that could modify the structure: chart_ax_x, but there is no delete argument.

John Smith
  • 1,604
  • 4
  • 18
  • 45
  • Could you share an example of your data using `dput()` and an example of your code? – neuron Dec 22 '21 at 21:28
  • Thank you neuron for your comment, I investigated more with `duput` and updated my question. – John Smith Dec 23 '21 at 09:32
  • 1
    @Xiaoshi You could try something like `chart_01[["x_axis"]][["delete"]] <- T`? Not sure that would have the intended consequence... – Ben Dec 23 '21 at 14:18

0 Answers0