Convert values into plot in a dataframe

I have a dataframe with dates and values as shown below

df <- read.table(header = T, text = 'ID  year    date    value
1   2019    1/1/2019    1
1   2019    1/2/2019    3
1   2020    1/1/2020    2
1   2020    1/2/2020    4
2   2019    1/1/2019    2
2   2019    1/2/2019    3
2   2020    1/1/2020    4
2   2020    1/2/2020    5')

is there way to convert these values into plots across dates and still put in a dataframe. Is there any package that helps in doing this

expected output. If you can see here plot column has plots across dates for these values

I just got this below stuff in google where I get almost I need.


mpg_list <- split(mtcars$mpg, mtcars$cyl)
disp_list <- split(mtcars$disp, mtcars$cyl)
inline_plot <- data.frame(cyl = c(4, 6, 8),mpg_points2 = "")
inline_plot %>%
  kbl(booktabs = TRUE) %>%
  kable_paper("hover", full_width = FALSE) %>%
  column_spec(2, image = spec_plot(mpg_list, disp_list, type = "p",same_lim = FALSE)) 


But can we have few features here ?
I need hover tooltip and also if you see the there is no secondary axis between 2 categories. All are in the same line

Inline plots are going to have a lot of limitations. They're meant to be very minimal. Do your plots have to be in a table? Can you use facet_wrap instead to make a grid of plots?

In table form only. Similar to kable package that I have mentioned :blush:

There's this example for inserting images into a kable table. You could write a script to save the individual images and put the filenames in a properly ordered vector. They won't have hover though.

tbl_img %>%
  kbl(booktabs = T) %>%
  kable_paper(full_width = F) %>%
  column_spec(2, image = spec_image(
    c("kableExtra_sm.png", "kableExtra_sm.png"), 50, 50))

I see. Can we not have a interactive plots with hovering?

Because I had asked about incorporating html in shiny Incorporating html tags in shiny - #4 by nirgrahamuk

The reason i asked this question is, if we can render these plots as a pure html tags. I can incorporate in dt table and make the plots :slight_smile:

Maybe... that goes outside my own personal experience.

You can insert html into a kable table by setting the argument escape = FALSE, so I guess it's possible to insert "html plots" into a table that have hover enabled in the html.

Yes it is possible. But the issue I am not able to insert HMTL javascripts directly. If you see my another question in the link i shared, we cannot directly paste html scripts :frowning:

Ok let me explain my end goal say my final dataframe is below

ID      plot

In this plot column I need to render plots as attached in my question. These plots are reactive and changes as per filters so we cannot put html static images. Similar to below image. Here the I can put it under datatable(df, excape = FALSE)where df is data with below values

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.