Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
1 year ago

Color and label failed to display after publishing R visuals (ggplot)

Hi all,

 

I'm trying to create a R visual in Power BI that colored and labeled some specific points in a scatterplot. The plot works fine in the Power BI Desktop, however, when I published the report, all the color and label disappear (same color for all points and no labels). Please see the screenshots below.

 And R code as follow:

ggplot(data = data1, aes(x = X, y = Y))+
                  geom_point(pch = 16, color = colorcurrent,size = 3)+
                  theme_minimal() +
                  geom_text_repel(aes(label = labelcurrent),size = 5, color = colorcurrent)
where labelcurrent and colorcurrent are vectors contianing the corresponding lable name or color for each observation, i.e. c("black", "blue", ....) and c("", "lableit", ...).
 

What do I need to do to get this working?

 

Thanks for your help in advance!

 

Regards,

Vanessa

 

4 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi, Anonymous 

    Start by checking which R packages the Power BI service supports you are using, such as ggplot2 and ggrepel. Sometimes, some versions of the package may not be fully compatible. Or try using a hexadecimal color code in the colorcurrent vector instead of using the color name. For example, c("#000000", "#0000FF", ... ) instead of c("black", "blue", ... ).
    Also make sure that labelcurrent and colorcurrent are properly formatted as character vectors. Sometimes, factors or other data types can cause problems.
    Try clearing the cache by going to File > Options & Settings > Options & Settings > Data Load > Clear Cache to clear the Power BI cache.
    If you're using a custom theme, make sure you apply it correctly and re-import it if necessary. After you make these changes, republish the report to the Power BI service.
    You can refer to the following post:

    Solved: Colours Change when report is published to the Ser... - Microsoft Fabric Community

     

    Based on your information, I create a sample data:

    Here is my preview:

    Then publih to service:

     

     

    If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data)

     

    How to Get Your Question Answered Quickly

    Best Regards

    Yongkang Hua

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Anonymous,

     

    Thanks for your reply! After going through your suggestions, my problem still exists. Attached please find my demo data, R code and related screenshot (as I can't attach a pbix file or Excel). Thanks!

     

    Demo data:

    GroupBatchXY
    ABatch 17671
    BBatch 14721
    CBatch 1530
    DBatch 14654
    EBatch 1257
    FBatch 18940
    GBatch 19368
    HBatch 12536
    IBatch 110091
    JBatch 15841
    KBatch 14629
    LBatch 11431
    MBatch 1940
    NBatch 13614
    OBatch 17790
    PBatch 19165
    QBatch 17095
    RBatch 17429
    SBatch 1287
    TBatch 12446
    UBatch 11536
    VBatch 17100
    WBatch 11366
    XBatch 15883
    YBatch 16170
    ZBatch 15135
    ABatch 2956
    BBatch 22465
    CBatch 22895
    DBatch 26114
    EBatch 26590
    FBatch 29861
    GBatch 26369
    HBatch 28064
    IBatch 29647
    JBatch 26221
    KBatch 24945
    LBatch 26452
    MBatch 23133
    NBatch 24350
    OBatch 22262
    PBatch 29086
    QBatch 22474
    RBatch 26871
    SBatch 26687
    TBatch 23149
    UBatch 2120
    VBatch 28817
    WBatch 21292
    XBatch 226
    YBatch 29815
    ZBatch 22684
    ABatch 37619
    BBatch 32564
    CBatch 31981
    DBatch 35911
    EBatch 38342
    FBatch 38750
    GBatch 3247
    HBatch 3032
    IBatch 34153
    JBatch 33696
    KBatch 32019
    LBatch 37334
    MBatch 38518
    NBatch 32850
    OBatch 33360
    PBatch 36259
    QBatch 37983
    RBatch 35726
    SBatch 31222
    TBatch 37413
    UBatch 34841
    VBatch 33923
    WBatch 36466
    XBatch 36429
    YBatch 32915
    ZBatch 39551
    ABatch 47684
    BBatch 45062
    CBatch 44765

     

    R code:

     

    # dataset <- data.frame(Group, Batch, X, Y)
    # dataset <- unique(dataset)
    
    # Paste or type your script code here:
    
    library(ggplot2)
    library(dplyr)
    library(ggrepel)
    
    number_of_batch<- 4
    
    data1<- dataset
    row.names(data1)<- paste0(data1$Group,"_B",gsub("[^0-9]", "",data1$Batch))
    
    labelcurrent<- rownames(data1)
    labelcurrent[! (labelcurrent %in% c(data1 %>% filter(Batch == paste0("Batch ", number_of_batch)) %>% rownames(.)))]<- ""
    # labelcurrent
    
    colorcurrent<- rep("black", nrow(data1))
    colorcurrent[rownames(data1) %in% c(data1 %>% filter(Batch == paste0("Batch ", number_of_batch)) %>% rownames(.))]<- "blue"
    
    
    ggplot(data = data1, aes(x = X, y = Y))+
                      geom_point(pch = 16, color = colorcurrent,size = 3)+
                      theme_minimal() +
                      geom_text_repel(aes(label = labelcurrent),size = 5, color = colorcurrent) 

     

     

    In Desktop previw:

    Published to service:

     

    Regards,

    Vanessa 

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi, Anonymous 

      I've noticed that when you work directly with column data, the label doesn't disappear when you upload it to the Power BI service.

      And the colors used are not applied to the Power BI service.

      Problems can arise with R code. This could be a breakthrough

       

      How to Get Your Question Answered Quickly

      Best Regards

      Yongkang Hua

      If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi, Anonymous 

      Have you solved your problem?