I tried to plot star plots with individual label in R but could not achieve it.
This is a picture of what I want my starplots to look like:
This is what I got after running the code below:
# loading package
library(fmsb)
# loading data
dac<- read_excel("Mean_data_ESS.xlsx")#reading from the .xlsx fil
daks<-select(dac, Pollinators,Flower_abundance,
Climate_regulation,Crop_area,
Plant_diversity,Nitrogen_balance,
Phosphorus_balance,Habitat_provision,
Recreation_covid,Aesthetic_appreciation,
Reconnection_nature,Mental_health,
Physical_health)
process <- preProcess(as.data.frame(daks), method=c("range"))
norm_datas <- predict(process, as.data.frame(daks))
stars(norm_datas[, 1:12], full = TRUE,radius = TRUE,len = 1.0,
key.loc = c(14,1),
labels = abbreviate(case.names(norm_datas)),
main = "Provision of Ecosystem services", draw.segments = TRUE,
lwd = 0.25, lty = par("lty"), xpd = TRUE)
Related
I am trying to create an heatmap with a row annotation inclusive of p-values as reported in the example in the guide for the use of the ComplexHeatmap package (https://jokergoo.github.io/ComplexHeatmap-reference/book/heatmap-annotations.html#simple-annotation).
I tried to reproduce the example:
library(ComplexHeatmap)
library(circlize) # colorRamp2 function
set.seed(123)
pvalue = 10^-runif(10, min = 0, max = 3)
is_sig = pvalue < 0.01
pch = rep("*", 10)
pch[!is_sig] = NA
# color mapping for -log10(pvalue)
pvalue_col_fun = colorRamp2(c(0, 2, 3), c("green", "white", "red"))
ha = HeatmapAnnotation(
pvalue = anno_simple(-log10(pvalue), col = pvalue_col_fun, pch = pch),
annotation_name_side = "left")
ht = Heatmap(matrix(rnorm(100), 10), name = "mat", top_annotation = ha)
# now we generate two legends, one for the p-value
# see how we define the legend for pvalue
lgd_pvalue = Legend(title = "p-value", col = pvalue_col_fun, at = c(0, 1, 2, 3),
labels = c("1", "0.1", "0.01", "0.001"))
# and one for the significant p-values
lgd_sig = Legend(pch = "*", type = "points", labels = "< 0.01")
# these two self-defined legends are added to the plot by `annotation_legend_list`
draw(ht, annotation_legend_list = list(lgd_pvalue, lgd_sig))
but when I am creating the annotation ha I get the error
Error in anno_simple(-log10(pvalue), col = pvalue_col_fun, pch = pch) :
could not find function "anno_simple"
likely showing a possible problem with the package.
The version of the ComplexHeatmap package I am running is 1.20.0.
The R version is 3.5.1.
Could you please help me solving this problem?
Thanks
I am using a particular R package called wTO (https://cran.r-project.org/web/packages/wTO/index.html)
One of the function which does the main computation also creates a plot among other things. As I am running the scripts on a CentOS server using SSH, I would like to save the plots. I am not sure where I should insert the commands for saving the plots. Kindly help.
The command is
> x= wTO.Complete(k = 32, n = 100, Data, Overlap, method = "p", method_resampling = "Bootstrap", pvalmethod = "BH", savecor = F, expected.diff = 0.2, lag = NULL, normalize = F, plot = T)
You need to open a graphic device before you call the function:
http://stat.ethz.ch/R-manual/R-devel/library/grDevices/html/png.html
After opening every plot will be written to this device until you call dev.off().
So you would do:
jpeg(filename = "yourname.jpeg")
x= wTO.Complete(k = 32, n = 100, Data, Overlap, method = "p", method_resampling = "Bootstrap", pvalmethod = "BH", savecor = F, expected.diff = 0.2, lag = NULL, normalize = F, plot = T)
dev.off()
You can then use/transfer your plot saved in yourname.jpeg.
I have SSIS package that gets data into database and then executes R Script. R script creates new folder (names it based on the current date) and generate some pdf files into this folder. I have deployed this package on server and created Job that executes it every night. The problem is that each morning I am finding only empty folders (with correct date name) without any pdf files. However, If I execute that package manually in Visual Studio it works fine and pdfs are there. Am I missing something here? I appreciate every answer.
EDIT
When I execute manually it is directly on the server
Package looks like this
and here is my R script
dir.create(file.path(output.path, date))
library(RODBC)
conn <- odbcConnect("Azure", uid = "aaaaa", pwd = "aaaaa")
etldata <- sqlFetch(conn,"dbo.EtlLogsData", stringsAsFactors = FALSE)
pdf(paste('ETL_Duration_For_Effective_Date_', date,'.pdf',sep = ""),
width = 12,
height = 8,
paper = 'special')
par(mar = c(5, 17, 5, 3))
plot(c(min(etldata_day$st_sec), max(etldata_day$et_sec)),
c(sn[1], sn[1]),
ylim = c(0, n),
yaxt = 'n',
xaxt = 'n',
ylab = '',
xlab = 'Time',
main = paste('ETL Duration With Effective Date ', date, sep = ""))
abline(h = sn, untf = FALSE, col = "gray90")
for (i in 1:n){
lines(c(etldata_day$st_sec[i], etldata_day$et_sec[i]),
c(sn[i], sn[i]),
type = "l", lwd = 2)
arrows(etldata_day$st_sec[i], sn[i],
etldata_day$et_sec[i], sn[i],
length = 0.025, angle = 90, lwd = 2)
arrows(etldata_day$et_sec[i], sn[i],
etldata_day$st_sec[i], sn[i],
length = 0.025, angle = 90, lwd = 2)
}
# Print y axis labels
axis(2, at = sn, labels = etldata_day$TaskName, las = 1, cex.axis = 1)
# Print x axis labels
xat <- seq(from = min(etldata_day$st_sec), to = max(etldata_day$et_sec), length.out = 10)
xlabels <- secondsToString(xat)
axis(1, at = xat, labels = substr(xlabels,1,8), cex.axis = 1)
dev.off()
After plot() I use some FOR cycles, and LINES(),
I am plotting a time series with the timePlot function of the open air package of R. The graph has grey grid lines in the background that I would like to turn off but I do not find a way to do it. I would expect something simple such as grid = FALSE, but that is not the case. It appears to be rather complex, requiring the use of extra arguments which are passed to xyplot of the library lattice. I believe the answer lies some where in the par.settings function but all attempts have failed. Does anyone have any suggestions to this issue?
Here is by script:
timeozone <- import(i, date="date", date.format = "%m/%d/%Y", header=TRUE, na.strings="")
ROMO = timePlot(timeozone, pollutant = c("C7", "C9", "C10"), group = TRUE, stack = FALSE,y.relation = "same", date.breaks = 9, lty = c(1,2,3), lwd = c(2, 3, 3), fontsize = 15, cols = c("black", "black"), ylab = "Ozone (ppbv)")
panel = function(x, y) {
panel.grid(h = 0, v = 0)
panel.xyplot(x,y)
}
I am trying to plot various events over a times series data set using chart.TimeSeries in the PerformanceAnalytics library. I have tried to follow the example from but I think I am missing something.
ExampleChart MyChart
Neither my vertical event lines nor are my period areas are showing up on the chart. My code is almost identical to the example code. Any ideas?
risk.dates = c(
"2015-04-19"
)
risk.labels = c(
"Jon Oliver's Patent Episode "
)
cycle.dates <- c ("2015-1-01/2015-01-31",
"2015-03-01/2015-03-31",
"2015-05-01/2015-05-31",
"2015-07-01/2015-07-31"
)
chart.TimeSeries(df, colorset = "darkblue",
date.format.in = "%Y-%m-%d",
legend.loc = NULL,
period.areas = cycles.dates,
period.color = "lightblue",
event.lines = risk.dates,
event.labels = risk.labels,
event.color = "red", lwd = 2,
main = "Reddit Sentiment Index",
auto.grid = FALSE)
df <- data.frame(DateTime=
c("2/17/2015","2/18/2015","2/19/2015",
"2/20/2015","2/21/2015","2/22/2015",
"2/23/2015","2/24/2015","2/25/2015",
"2/26/2015","2/27/2015","2/28/2015",
"2/28/2015","2/27/2015"),
AvgSentimentScore=
c("NA","NA","NA","NA","NA","NA","NA","NA","NA",
"8.405975696","8.313470536","8.414560335",
"8.720865075","9.284902246"))