Advance your Data & AI career with 50 days of live learning, dataviz contests, hands-on challenges, study groups & certifications and more!
Get registeredGet Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now
I have a script which when entered into Microsoft R Open version GUI I get one chart displayed which is correct. However, when using precisely the same code within Power BI, the segments of the pie chart do not colorate with those from the R GUI?
The code is pasted below:
library(ggplot2)
library(scales)
blank_theme <- theme_minimal() +
theme(
plot.title = element_text(size=16, face="bold"),
axis.title = element_blank(),
axis.title.x = element_blank(),
axis.title.y = element_blank(),
axis.ticks = element_blank(),
axis.text.y = element_blank(),
axis.text.x = element_text(color='black'),
panel.grid = element_blank()
)
df <- data.frame(
value = c(6019, 2211, 314),
Legend = c("Registered Within", "Registered On", "Registered Out")
)
p <- ggplot(df, aes(x=1, y=value, fill=Legend))+
ggtitle("Registered DETs 4am") +
coord_polar(theta='y')
y.breaks <- cumsum(df$value) - df$value / 2
p <- p +
scale_fill_manual(values=c("#FD625E", "#F2C80F", "#01B8AA"))+
geom_bar(stat="identity", color="black") +
guides(fill=guide_legend(override.aes=list(colour=NA))) +
blank_theme +
theme(axis.text.x=element_blank()) +
scale_y_continuous(
breaks = y.breaks,
labels=df$Legend
) +
geom_text(
aes(
y = value / 3 + c(0, cumsum(value)[-length(value)]),
label = format(value/sum(value)*100, digits=2, nsmall=2)
),
size=4
) +
labs(
title="Registered DETs - 04:00"
)
p
Everything is contained within the code above, for this to be tested.
In the R GUI, the order is "Registered In", "Registered On", "Registered Out" along with the correct data, however, in Power BI, the labels are ordered correctly, but the segments are drawn in the order of "Registered In", "Registered Out", "Registered On".
Does anyone know why this is the case?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.