Supplies are limited. Contact info@espc.tech right away to save your spot before the conference sells out.
Get your discountScore big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount
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)
What do I need to do to get this working?
Thanks for your help in advance!
Regards,
Vanessa
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:
Group | Batch | X | Y |
A | Batch 1 | 76 | 71 |
B | Batch 1 | 47 | 21 |
C | Batch 1 | 53 | 0 |
D | Batch 1 | 46 | 54 |
E | Batch 1 | 25 | 7 |
F | Batch 1 | 89 | 40 |
G | Batch 1 | 93 | 68 |
H | Batch 1 | 25 | 36 |
I | Batch 1 | 100 | 91 |
J | Batch 1 | 58 | 41 |
K | Batch 1 | 46 | 29 |
L | Batch 1 | 14 | 31 |
M | Batch 1 | 94 | 0 |
N | Batch 1 | 36 | 14 |
O | Batch 1 | 77 | 90 |
P | Batch 1 | 91 | 65 |
Q | Batch 1 | 70 | 95 |
R | Batch 1 | 74 | 29 |
S | Batch 1 | 2 | 87 |
T | Batch 1 | 24 | 46 |
U | Batch 1 | 15 | 36 |
V | Batch 1 | 7 | 100 |
W | Batch 1 | 13 | 66 |
X | Batch 1 | 58 | 83 |
Y | Batch 1 | 61 | 70 |
Z | Batch 1 | 51 | 35 |
A | Batch 2 | 95 | 6 |
B | Batch 2 | 24 | 65 |
C | Batch 2 | 28 | 95 |
D | Batch 2 | 61 | 14 |
E | Batch 2 | 65 | 90 |
F | Batch 2 | 98 | 61 |
G | Batch 2 | 63 | 69 |
H | Batch 2 | 80 | 64 |
I | Batch 2 | 96 | 47 |
J | Batch 2 | 62 | 21 |
K | Batch 2 | 49 | 45 |
L | Batch 2 | 64 | 52 |
M | Batch 2 | 31 | 33 |
N | Batch 2 | 43 | 50 |
O | Batch 2 | 22 | 62 |
P | Batch 2 | 90 | 86 |
Q | Batch 2 | 24 | 74 |
R | Batch 2 | 68 | 71 |
S | Batch 2 | 66 | 87 |
T | Batch 2 | 31 | 49 |
U | Batch 2 | 12 | 0 |
V | Batch 2 | 88 | 17 |
W | Batch 2 | 12 | 92 |
X | Batch 2 | 2 | 6 |
Y | Batch 2 | 98 | 15 |
Z | Batch 2 | 26 | 84 |
A | Batch 3 | 76 | 19 |
B | Batch 3 | 25 | 64 |
C | Batch 3 | 19 | 81 |
D | Batch 3 | 59 | 11 |
E | Batch 3 | 83 | 42 |
F | Batch 3 | 87 | 50 |
G | Batch 3 | 2 | 47 |
H | Batch 3 | 0 | 32 |
I | Batch 3 | 41 | 53 |
J | Batch 3 | 36 | 96 |
K | Batch 3 | 20 | 19 |
L | Batch 3 | 73 | 34 |
M | Batch 3 | 85 | 18 |
N | Batch 3 | 28 | 50 |
O | Batch 3 | 33 | 60 |
P | Batch 3 | 62 | 59 |
Q | Batch 3 | 79 | 83 |
R | Batch 3 | 57 | 26 |
S | Batch 3 | 12 | 22 |
T | Batch 3 | 74 | 13 |
U | Batch 3 | 48 | 41 |
V | Batch 3 | 39 | 23 |
W | Batch 3 | 64 | 66 |
X | Batch 3 | 64 | 29 |
Y | Batch 3 | 29 | 15 |
Z | Batch 3 | 95 | 51 |
A | Batch 4 | 76 | 84 |
B | Batch 4 | 50 | 62 |
C | Batch 4 | 47 | 65 |
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
Hi, @Vanessa_VW
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.
Hi, @Vanessa_VW
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.