Error while converting ggplot to plotly

I have a ggplot which I am trying to convert to plotly and I get the following error. I have added the code with the error. I did update plotly .

library(ggplot2)
library(plotly)


spend_opt_tv <-tibble::tribble(
  ~Channel,   ~Network,                 ~Daypart,        ~Lower,     ~Current,          ~Upper, ~Optimized.Budget,        ~CPM,
  "TV 1",      "NBC",                  "Other",  "$13,790.50",    "$27,581",    "$41,371.50",         "$41,372", "$4,555.00",
  "TV 2",      "NBC",      "Weekday Afternoon",  "$97,680.00",   "$195,360",   "$293,040.00",        "$237,904", "$3,964.00",
  "TV 3",      "NBC",   "Weekday Early Fringe", "$160,129.50",   "$320,259",   "$480,388.50",        "$160,132", "$4,190.00",
  "TV 4",      "NBC",    "Weekday Late Fringe", "$110,546.00",   "$221,092",   "$331,638.00",        "$185,136", "$4,491.00",
  "TV 5",      "NBC",        "Weekday Morning", "$226,253.00",   "$452,506",   "$678,759.00",        "$354,960", "$6,206.00",
  "TV 6",      "NBC",               "Weekends",  "$35,880.00",    "$71,760",   "$107,640.00",        "$107,640", "$4,147.00",
  "TV 7",      "CBS",                  "Other",  "$95,873.50",   "$191,747",   "$287,620.50",        "$238,774", "$5,145.00",
  "TV 8",      "CBS",             "Prime Time",  "$57,645.00",   "$115,290",   "$172,935.00",         "$57,647", "$3,951.00",
  "TV 9",      "CBS",               "Weekends",  "$18,915.00",    "$37,830",    "$56,745.00",         "$56,747", "$3,531.00"
)

plot <- ggplot(spend_opt_tv, aes(x = Daypart, y = Current, fill = Daypart)) +
  geom_col(show.legend = FALSE) +
  facet_grid(Network ~ ., switch = "y", scales="free") +
  coord_flip() +
  theme_classic() + 
  scale_fill_brewer(palette="Spectral") +
  theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
  theme(axis.title.y = element_blank())

ggplotly(plot)
#> Error: .onLoad failed in loadNamespace() for 'Cairo', details:
#>   call: dyn.load(file, DLLpath = DLLpath, ...)
#>   error: unable to load shared object '/Library/Frameworks/R.framework/Versions/3.5/Resources/library/Cairo/libs/Cairo.so':
#>   dlopen(/Library/Frameworks/R.framework/Versions/3.5/Resources/library/Cairo/libs/Cairo.so, 6): Library not loaded: /opt/X11/lib/libfreetype.6.dylib
#>   Referenced from: /Library/Frameworks/R.framework/Versions/3.5/Resources/library/Cairo/libs/Cairo.so
#>   Reason: image not found

Created on 2019-01-31 by the reprex package (v0.2.1.9000)

Are you on Mac OS? do you have library Cairo installed?
If you are on Mac OS try installing/reinstalling xquartz
https://www.xquartz.org/

3 Likes

Thank you. That worked.

This topic was automatically closed 7 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.