Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
ZviR
Frequent Visitor

R script that plot perfectly in Rstudio dose not plot completely in PBI

Hello,

I've ploted a bar chart with standart error in Rstudio, when addapted it to BPI only the frame  was ploted with no bars or se.

please help finding and resolving the problem.

Thanks,

Z

Please find the script and the Rstudio plot:

library(ggplot2)
library(Rmisc)
library(tidyr)
## Source file  Directory  ##

SourcWD<-"C:\\Users\\Lenovo\\Desktop\\BI-O\\Data Files"

setwd(SourcWD)

##  Loading File as dataset  ##
dataset<-read.csv(file="C:\\Users\\Lenovo\\Desktop\\BI-O\\Data Files\\caa.csv", header = TRUE, sep = ",")
attach(dataset)
dataset



# Converting from Wide to Long

keycol <- "Type"
valuecol <- "Mean"
gathercols <- c("CAA.Percent", "CAA.Potency")

dataset_long<-gather_(dataset, keycol, valuecol, gathercols)

#Summerizing

dataset_data <- summarySE(dataset_long, measurevar="Mean","Type")
dataset_data

#Ploting

ggplot(dataset_data, aes(x=Type, y=Mean, fill=Type)) + 
  geom_bar(position=position_dodge(), stat="identity",
           colour="black", # Use black outlines,
           size=.3) +      # Thinner lines
  geom_errorbar(aes(ymin=Mean-sd, ymax=Mean+sd),
                size=1,    # Thinner lines
                width=.3,
                position=position_dodge(.1)) +
  xlab(" Test ") +
  ylab("Results") +
  scale_fill_hue(name="Test type", # Legend label, use darker colors
                 labels=c("CAA %", "CAA Potency")) +
  ggtitle("CAA (%) vs. CAA Potency") +
  scale_y_continuous(breaks=0:20*4) +
  theme_bw()

and the plot:

BARWSE.jpg

 

Also please find the BPI code:

library(data.table, quietly = TRUE);
library(ggplot2, quietly = TRUE); 
library(tidyr, quietly = TRUE); 
library(Rmisc, quietly = TRUE); 
attach(dataset)

#dataset$Batch <- factor(dataset$Batch)
keycol <- "Type"
valuecol <- "Mean"
gathercols <- c("CAA.Percent", "CAA.Potency")

dataset_long<-gather_(dataset, keycol, valuecol, gathercols)
dataset_data <- summarySE(dataset_long, measurevar="Mean","Type")

ggplot(dataset_data, aes(x=Type, y=Mean, fill=Type)) + 
geom_bar(position=position_dodge(), stat="identity",
colour="black", # Use black outlines,
size=.3) +      # Thinner lines
geom_errorbar(aes(ymin=Mean-sd, ymax=Mean+sd),
size=.5,    # Thinner lines
width=.3,
position=position_dodge(.9)) +
xlab(" Test ") +
ylab("Results") +
scale_fill_hue(name="Test type", # Legend label, use darker colors
labels=c( "CAA %","CAA Potency")) +
  ggtitle("CAA (%) vs. CAA Potency") +
  scale_y_continuous(breaks=0:20*4) +
  theme_bw()

and the empty plot:

PBI NO PLOT.jpg

2 REPLIES 2
ankitpatira
Community Champion
Community Champion

@ZviR can you also provide csv file or sample data so that I can troubleshoot your issue.

Batch	CAA Percent	CAA Potency 
R15	78	110
R16	79	114
R17	92	123
R19	74	109
R21	76	107
R24	61	84
R25	65	90
R26	66	94
R27	80	102

Thanks,

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

Find out what's new and trending in the Fabric community.