Rep function in r for forest plots - r

I am trying to create a forest plot and although this works for my other datasets, the shapes are not working and doing what I want them do with this dataset. Each cohort is represented by a diamond or a circle and then each age group is represented by a colour. With this code, I keep on getting circles for both cohorts and then diamonds for both cohorts:
Code:
tiff('replication_diet_subset1_risk_diff.tiff',units = "cm",width=16,height=16,res=600)
tt1=cbind(replication_diet_subset1$Description)
forestplot(tt1, mean = cbind(replication_diet_subset1$coef.1,replication_diet_subset1$coef1_hunt,replication_diet_subset1$coef.2,replication_diet_subset1$coef2_hunt,replication_diet_subset1$coef.3,replication_diet_subset1$coef3_hunt),
lower = cbind(replication_diet_subset1$lower.1, replication_diet_subset1$lci_coef1_hunt,replication_diet_subset1$lower.2,replication_diet_subset1$lci_coef2_hunt,replication_diet_subset1$lower.3,replication_diet_subset1$lci_coef3_hunt),
upper = cbind(replication_diet_subset1$upper.1,replication_diet_subset1$uci_coef1_hunt, replication_diet_subset1$upper.2,replication_diet_subset1$uci_coef2_hunt,replication_diet_subset1$upper.3,replication_diet_subset1$uci_coef3_hunt),
lwd.xaxis=1,
xlog=FALSE,
graph.pos = 2,
zero = 0,
lwd.zero = 1.5,
boxsize = 0.08,
lty = 1,
col=fpColors(box=rep(c("blue", "darkred", "darkgreen"),each=2),line=rep(c("blue", "darkred", "darkgreen"),each=2)),
fn.ci_norm=rep(c(fpDrawDiamondCI,fpDrawCircleCI),3),
legend = c("UK 39-53y","UN 39-53y","UK 53-62y","UN 53-62y","UK 62-72y","UN 62-72y"),
lwd.ci = 1.5, ##thickness of the CI line,
xticks = c(-0.05,0,0.05),
xlab ="coefficient (95% CI)",las = 10,
is.summary = FALSE,
txt_gp = fpTxtGp(xlab = gpar(cex=0.6),##changes font size of xlabel
ticks = gpar(cex=0.6),
legend=gpar(cex=0.55),
label = list(gpar(cex=0.6),
gpar(cex=0.8))),
hrzl_lines=list("2" = gpar(lty=2, lwd=1), "3" = gpar(lty=2, lwd=1),"4" = gpar(lty=2, lwd=1)),
legend_args=fpLegend(pos = list(x=0.1,y=-0.10, "align"="horizontal",gpar(lwd=1, lty=1), padding=unit(ifelse(!is.null(forestplot), 0.6, 0.6), "mm"))))
Dataframe
dput(replication_diet_subset1)
structure(list(Description = c("Fresh fruit intake", "Lamb/mutton intake",
"Non-oily fish intake", "Oily fish intake", "Water intake", "Salad/raw vegetable intake"
), coef1_hunt = c(-0.00743, 0.002942, 0.00236, -0.00743, 0.005049,
0.003846), se...3 = c(0.007141, 0.005758, 0.005443, 0.007141,
0.006629, 0.006245), lci_coef1_hunt = c(-0.02142636, -0.00834368,
-0.00830828, -0.02142636, -0.00794384, -0.0083942), uci_coef1_hunt = c(0.00656636,
0.01422768, 0.01302828, 0.00656636, 0.01804184, 0.0160862), ...6 = c(16635,
9728, 9725, 16635, 23278, 16635), coef2_hunt = c(-0.002244, -0.00276,
0.000345, -0.002244, -0.00151, -0.000206), se...8 = c(0.008917,
0.006276, 0.006188, 0.008917, 0.009408, 0.007517), lci_coef2_hunt = c(-0.01972132,
-0.01506096, -0.01178348, -0.01972132, -0.01994968, -0.01493932
), uci_coef2_hunt = c(0.01523332, 0.00954096, 0.01247348, 0.01523332,
0.01692968, 0.01452732), ...11 = c(9897, 7545, 7567, 9897, 9915,
9867), coef3_hunt = c(0.019017, -0.007802, -0.006307, 0.019017,
0.005309, -0.002412), se...13 = c(0.005753, 0.004112, 0.003982,
0.005753, 0.008282, 0.004975), lci_coef3_hunt = c(0.00774112,
-0.01586152, -0.01411172, 0.00774112, -0.01092372, -0.012163),
uci_coef3_hunt = c(0.03029288, 0.000257520000000001, 0.00149772,
0.03029288, 0.02154172, 0.007339), ...16 = c(25536, 17792,
17907, 25536, 14181, 25575), coef.1 = c(0.00362314944509158,
-0.00470790257232875, 0.000345069788105902, 0.00119994747831877,
0.00366026474163439, 0.00452057277808969), lower.1 = c(0.000100809813626033,
-0.00870031842036767, -0.00444673772605906, -0.00415468715681286,
-0.00142385548036369, 0.000495870575295929), upper.1 = c(0.00714548907655713,
-0.000715486724289832, 0.00513687730227086, 0.0065545821134504,
0.00874438496363247, 0.00854527498088346), coef.2 = c(0.00652712910056686,
-0.008389394817565, 0.00385312798368479, 0.00684123232489216,
0.00820481571195358, 0.00206021000034981), lower.2 = c(0.0031064649063915,
-0.0124479794653457, -0.000643937452513724, 0.00152183943585278,
0.00305901182100011, -0.00191718709478407), upper.2 = c(0.00994779329474222,
-0.00433081016978427, 0.00835019341988331, 0.0121606252139315,
0.0133506196029071, 0.00603760709548368), coef.3 = c(0.00801099623452188,
-0.0108977910125354, 0.0115185369443351, 0.0167317285202842,
0.0153438933855643, 0.0101781793610485), lower.3 = c(0.00465798740347312,
-0.0150517577821998, 0.00721508140505276, 0.0114866825853908,
0.0101968058956273, 0.00609905055235197), upper.3 = c(0.0113640050655706,
-0.00674382424287112, 0.0158219924836174, 0.0219767744551776,
0.0204909808755013, 0.0142573081697451)), row.names = c(NA,
-6L), class = c("tbl_df", "tbl", "data.frame"))
dev.off()
I would really appreciate your advice!
TIA

Related

Why do RadarCharts graph incorrectly in R? (fmsb)

create_beautiful_radarchart <- function(data, color = "#800000",
vlabels = colnames(data), vlcex = 0.7,
caxislabels = NULL, title = NULL, ...){
radarchart(
data, axistype = 1,
pcol = color, pfcol = scales::alpha(color, 0.5), plwd = 2, plty = 1,
cglcol = "grey", cglty = 1, cglwd = 0.8,
axislabcol = "grey",
vlcex = vlcex, vlabels = vlabels,
caxislabels = caxislabels, title = title, ...
)
}
colors <- c("#00AFBB", "#E0115F", "#800000", "orange")
titles <- c("UnderWeight", "NormalWeight", "OverWeight", "Obese")
for(i in 1:4){
create_beautiful_radarchart(
data = df[c(1,2,3,4),], caxislabels = c(5000,10000,15000,20000),
color = colors[i], title = titles[i],
seg=3)
}
Why does my code produce radarcharts like:
Here is my entire dataset:
NORTHEAST
NORTHWEST
SOUTHEAST
SOUTHWEST
UNDERWEIGHT
8914.424
9223.351
0.00
7778.771
NORMALWEIGHT
11151.782
10032.507
13286.81
7246.518
OVERWEIGHT
10818.594
11503.929
10846.20
10786.970
OBESE
16606.763
14198.111
16139.57
14752.032
The first two rows of your data frame have to be the maximum and minimum values you want plotted for that series. Since you are filling the areas, you will need to make the colors for the macimum and minimum values NA. You can automate the ranges for each series like this:
range <- as.data.frame(lapply(df, function(x) rev(range(pretty(x)))))
And presumably you want 4 separate radar plots, in which case you can do:
for(i in 1:4){
create_beautiful_radarchart(
data = rbind(range, df[i,]), caxislabels = c(5000,10000,15000,20000),
color = c(NA, NA, colors[i]), title = titles[i],
seg=3)
}

How to adjust column width in dataframe of foretsplotter function

I am trying to create a forestplot, using forestplotter function, am able to get a beautiful graph, but am not able to see the entire graph, the column widths in few of the columns are so big, even if the string size is less, making the width of the entire graph, so big to see, can someone help me with this and also is it possible to align the datahrame contents uniformly centre aligned......Please help me with this
The code and relevant data are
###Required packages###
library(grid)
library(forestploter)
library(rmeta)
library(gridExtra)
#Data entered#
df <- data.frame(Study=c("A","B","C","D","Summary"),
nA = c(24,187,36,26,273),
median_A = c(4.9,5.69,8.866995074,8.5,NA),
Q1A =c(3,2.86,4.495073892,2,NA),
Q3A =c(8.5,9.78,14.96305419,32,NA),
nP = c(23,193,36,26,278),
median_P = c(7.2,6.79,8.990147783,12.5,NA),
Q1P =c(3.4,3.59,4.002463054,2,NA),
Q3P =c(10.9,10.12,12.06896552,43,NA),
W = c("10.6%","80.8%","8.0%","0.70%",NA),
E=c(-2.3,-1.1,-0.123152709,-4,-1.16881587),
UL=c(1.161473203,0.156288294,3.881699516,10.02689306,-0.039791047),
LL=c(-5.761473203,-2.356288294,-4.128004935,-18.02689306,-2.297840692))
#Calculate SE for box size#
df$SE <- (df$UL-df$E)/1.96
#Column for Confidence intervals for Drug A and Placebo, with 2 significant digit#
df$IQRA <- sprintf("%.2f (%.2f to %.2f)",df$median_A,df$Q1A, df$Q3A)
df$IQRP <- sprintf("%.2f (%.2f to %.2f)",df$median_P,df$Q1P, df$Q3P)
#Column for Confidence intervals for NET EFFECT, with 2 significant digit#
df$MD <- sprintf("%.2f (%.2f to %.2f)", df$E, df$LL, df$UL)
#Create a column with space for forest plot#
df$" "<- paste(rep(" ", 16), collapse = " ")
##Forest plot theme##
#To be modified as needed#
ftn <-forest_theme(
base_size = 16,
base_family = "serif",
ci_pch = 15,
ci_col = "black",
ci_lty = 1,
ci_lwd = 1,
ci_Theight = 0.25,
legend_name = " ",
legend_position = "right",legend_value = "",
xaxis_lwd = 1,
xaxis_cex = 0.7,
refline_lwd = 1,
refline_lty = "dashed",
refline_col = "red",
summary_fill = "blue",
summary_col = "blue",
footnote_cex = 0.4,
footnote_fontface = "plain",
footnote_col = "black",
title_just = c("center"),
title_cex = 1.1,
title_fontface = "bold",
title_col = "black",
show.rownames = FALSE)
##Table in Order for Forest plot##
#First get Column names#
colnames(df)
df2 <-df[,c(1,2,15,6,16,18,17)]
#Make NA cells empty
df2[5,3] <-c(" ")
df2[5,5] <-c(" ")
##Forestplot##
plot<-forest(df2,
est = df$E,
lower = df$LL,
upper = df$UL,
sizes = (df$SE/10),
ci_column = 6,
ref_line = 0,
arrow_lab = c("Drug A Better", "Placebo Better"),
xlim = c(-7, 6),
is_summary = c(FALSE,FALSE,FALSE,FALSE,TRUE),
xlog = FALSE,
ticks_digits = 0,ticks_at = c(-6,0,6),
theme = ftn)
##Show plot
print(plot, autofit = FALSE)

Remove specific markers from legend

Sorry if this question has already been answered but I could not find the solution to what I am after. I have a plot that uses both geom_line and geom_point. The result of this is that in the legend, it adds both a line and a point when they should have one or the other. I want to keep the circles for the data tg1 and tg2 and remove the line and then do the opposite to the data full i.e. keep the line but remove the circle. I have seen that something like this works where you want to remove dots from all of the legend entries but nothing to only do specifics Removing ggplot2's geom_point icons from the legend. Can anyone help? Thanks.
#code for plot
library(ggplot2)
library(tidypaleo)
ggplot(LGRSL, aes(x =mmsl , y = Age))+
coord_flip()+
theme_classic(12)+
geom_point(data=tg1,aes(x=mmslc,y=Year,col="Fort Denison 1"),pch=1,size=2)+
geom_point(data=tg2,aes(x=mmslc,y=Year,col="Fort Denison 2"),pch=1,size=2)+
geom_lineh(data = full, aes(x=Lutregalammslc,y=Year,col="Full budget"))+
scale_colour_manual(values=c("grey15","grey50","black"))
## data
## tg1
structure(list(Year = 1886:1891, SLR = c(6919L, 6935L, 6923L,
6955L, 6956L, 6957L), mmsl = c(-0.158, -0.142, -0.154, -0.122,
-0.121, -0.12), m = c(6.919, 6.935, 6.923, 6.955, 6.956, 6.957
), GIA.correction = c(-0.02814, -0.02793, -0.02772, -0.02751,
-0.0273, -0.02709), SLRc = c(6.89086, 6.90707, 6.89528, 6.92749,
6.9287, 6.92991), mmslc = c(-0.19667, -0.18046, -0.19225, -0.16004,
-0.15883, -0.15762)), row.names = c(NA, 6L), class = "data.frame")
##tg2
structure(list(Year = 1915:1920, SLR = c(7011L, 6929L, 6987L,
6945L, 6959L, 6951L), mmsl = c(-0.066, -0.148, -0.09, -0.132,
-0.118, -0.126), m = c(7.011, 6.929, 6.987, 6.945, 6.959, 6.951
), GIA.correction = c(-0.02205, -0.02184, -0.02163, -0.02142,
-0.02121, -0.021), SLRc = c(6.98895, 6.90716, 6.96537, 6.92358,
6.93779, 6.93), mmslc = c(-0.09858, -0.18037, -0.12216, -0.16395,
-0.14974, -0.15753)), row.names = c(NA, 6L), class = "data.frame")
##full
structure(list(Year = 1900:1905, Lutregala = c(-0.103609677,
-0.118603251, -0.134550791, -0.105553735, -0.103983082, -0.121731984
), Wapengo = c(-0.095213147, -0.096005337, -0.115700625, -0.097696891,
-0.084444784, -0.109161066), Tarra = c(-0.106672829, -0.109537943,
-0.135256365, -0.101357772, -0.089716518, -0.104258351), Lutregalammsl = c(-0.292863465,
-0.307857039, -0.323804579, -0.294807523, -0.29323687, -0.310985772
), Wapengommsl = c(-0.257028279, -0.257820469, -0.277515756,
-0.259512023, -0.246259916, -0.270976198), Tarrammsl = c(-0.30925682,
-0.312121933, -0.337840355, -0.303941762, -0.292300508, -0.306842342
), LgGIAc = c(-0.01921, -0.01904, -0.01887, -0.0187, -0.01853,
-0.01836), WapGIAc = c(-0.02486, -0.02464, -0.02442, -0.0242,
-0.02398, -0.02376), TarGIAc = c(-0.02373, -0.02352, -0.02331,
-0.0231, -0.02289, -0.02268), Lutregalammslc = c(-0.312073465,
-0.326897039, -0.342674579, -0.313507523, -0.31176687, -0.329345772
), Wapmmslc = c(-0.281888279, -0.282460469, -0.301935756, -0.283712023,
-0.270239916, -0.294736198), Tarmmslc = c(-0.33298682, -0.335641933,
-0.361150355, -0.327041762, -0.315190508, -0.329522342)), row.names = c(NA,
6L), class = "data.frame")
##LGRSL
structure(list(depths = c(0.5, 1.5, 2.5, 3.5, 4.5, 5.5), RSL = c(0.047746907,
0.025564293, 0.021733558, 0.007855661, -0.004909879, 0.01747051
), RSLerror = c(0.058158556, 0.057902654, 0.057988654, 0.057957388,
0.057905405, 0.057226072), Age = c(2017.456716, 2013.594255,
2006.92838, 1999.675523, 1994.729181, 1990.518154), Ageerror = c(0.373138707,
0.77640096, 1.430582242, 1.627131115, 3.222393394, 3.239674718
), mmsl = c(0.01993169, -0.002250924, -0.006081659, -0.019959556,
-0.032725096, -0.010344707)), row.names = c(NA, 6L), class = "data.frame")
##LGRSLgp
structure(list(Age = 1892:1897, mean = c(-0.298147401, -0.304630597,
-0.31023294, -0.315506983, -0.321225142, -0.327190675), error = c(0.051858047,
0.04985084, 0.047760525, 0.045624121, 0.043505044, 0.041477551
), min = c(-0.246289354, -0.254779758, -0.262472416, -0.269882862,
-0.277720098, -0.285713124), max = c(-0.350005447, -0.354481437,
-0.357993465, -0.361131103, -0.364730186, -0.368668226), x = c(-0.02125,
-0.02108, -0.02091, -0.02074, -0.02057, -0.0204), meangia = c(-0.276897401,
-0.283550597, -0.28932294, -0.294766983, -0.300655142, -0.306790675
), rate = c(NA, -4.967327, -4.946326, -4.964493, -4.977451, -4.911859
), raterror = c(NA, 3.581013, 3.796417, 4.022157, 4.226762, 4.255126
), mmsl = c(-0.325962618, -0.332445814, -0.338048157, -0.3433222,
-0.349040359, -0.355005892)), row.names = c(NA, 6L), class = "data.frame")
Here is a way.
Override the guide legend with a list of vectors of values for each of the aesthetics involved, shape and linetype. Note the different ways to specify what is to be removed.
I have also simplified the code a bit.
library(ggplot2)
library(dplyr)
colrs <- c("Fort Denison 1" = "grey15",
"Fort Denison 2" = "grey50",
"Full budget" = "black")
legnd <- list(shape = c(1, 1, NA),
linetype = c("blank", "blank", "solid"))
bind_rows(
tg1 %>% mutate(col = "Fort Denison 1"),
tg2 %>% mutate(col = "Fort Denison 2")
) %>%
ggplot(aes(x = mmslc, y = Year, colour = col)) +
geom_point(pch = 1, size = 2) +
geom_lineh(data = full, aes(x = Lutregalammslc, col = "Full budget"))+
scale_colour_manual(values = colrs,
guide = guide_legend(override.aes = legnd)) +
coord_flip() +
theme_classic(base_size = 12)

How to make a nice 3D plot in R for time series spectral data

I am trying to do a nice 3D plot using time series UV-Vis spectral data, like the first 3D graph below.
I used dput() function to show my data as below.
dput(head(Data))
and get:
structure(list(Wavelength = c(250, 252.5, 255, 257.5, 260, 262.5
), Date = structure(c(1365465600, 1365552000, 1365638400, 1365724800,
1365811200, 1365897600), class = c("POSIXct", "POSIXt"), tzone = "UTC"),
X250 = c(25.736217791411, 25.1182597222222, 24.8889567642957,
24.4881150070126, 24.2313916666667, 24.0346564673157), X252.5 = c(25.2168558282209,
24.6022625, 24.375429567643, 23.979541374474, 23.7248569444444,
23.5341668984701), X255 = c(24.6049539877301, 23.9896638888889,
23.7649888423989, 23.3753758765778, 23.1248263888889, 22.9342726008345
), X257.5 = c(24.0257944785276, 23.4037875, 23.1804435146443,
22.795541374474, 22.5493486111111, 22.35478581363), X260 = c(23.5917024539877,
22.9615486111111, 22.7389818688982, 22.3544109396914, 22.1091222222222,
21.9127635605007), X262.5 = c(23.1529110429448, 22.5264,
22.3051380753138, 21.924920056101, 21.6777583333333, 21.4858831710709
), X265 = c(22.5382085889571, 21.918125, 21.6982092050209,
21.3252145862553, 21.0800125, 20.8941794158554), X267.5 = c(21.8748957055215,
21.2488722222222, 21.0308619246862, 20.6643941093969, 20.4225541666667,
20.2340041724617), X270 = c(21.2791380368098, 20.6435263888889,
20.4248619246862, 20.0633674614306, 19.823075, 19.6308664812239
), X272.5 = c(20.7223159509202, 20.0815388888889, 19.8637377963738,
19.5049382889201, 19.2644375, 19.0733532684284), X275 = c(20.1307699386503,
19.4878583333333, 19.2719930264993, 18.9178920056101, 18.6778583333333,
18.487123783032), X277.5 = c(19.4758159509202, 18.8334013888889,
18.6168423988842, 18.2683702664797, 18.0308791666667, 17.8428414464534
), X280 = c(18.8002392638037, 18.1555375, 17.9391743375174,
17.5960126227209, 17.3601361111111, 17.1767204450626), X282.5 = c(18.1441809815951,
17.4953208333333, 17.2798758716876, 16.9426002805049, 16.7091777777778,
16.5276926286509), X285 = c(17.5349570552147, 16.8845097222222,
16.6697126917713, 16.337541374474, 16.1053763888889, 15.9246383866481
), X287.5 = c(16.8937300613497, 16.2423861111111, 16.0298493723849,
15.7046171107994, 15.4740472222222, 15.2938845618915), X290 = c(16.2328404907975,
15.582175, 15.3718940027894, 15.0537826086957, 14.8253291666667,
14.646668984701), X292.5 = c(15.5751472392638, 14.9258291666667,
14.7170446304045, 14.4051360448808, 14.1804194444444, 14.0051933240612
), X295 = c(14.9421717791411, 14.2904180555556, 14.0835034867504,
13.778301542777, 13.5566902777778, 13.3817329624478), X297.5 = c(14.4052392638037,
13.7537152777778, 13.5474421199442, 13.2471725105189, 13.0260375,
12.8530055632823), X300 = c(13.9050889570552, 13.2578347222222,
13.0537364016736, 12.7592973352034, 12.5405888888889, 12.3732670375522
), X302.5 = c(13.401036809816, 12.7586194444445, 12.5570264993026,
12.2684992987377, 12.0533902777778, 11.8884353268428), X305 = c(12.902717791411,
12.2623319444444, 12.0613933054393, 11.7787826086956, 11.5651972222222,
11.4043337969402), X307.5 = c(12.4249355828221, 11.7857791666667,
11.5858940027894, 11.3107840112202, 11.0999777777778, 10.9374005563282
), X310 = c(11.9935245398773, 11.3549347222222, 11.1571324965133,
10.8868260869565, 10.67955, 10.5179193324061), X312.5 = c(11.6203098159509,
10.9819680555556, 10.7849539748954, 10.516744740533, 10.3119236111111,
10.156892906815), X315 = c(11.2705674846626, 10.63485, 10.4406555090656,
10.177301542777, 9.97497638888889, 9.82023783031989), X317.5 = c(10.9098711656442,
10.2797055555556, 10.0875216178522, 9.82828471248247, 9.62720138888889,
9.47325173852573), X320 = c(10.5516625766871, 9.922075, 9.73211157601116,
9.47973772791024, 9.28055, 9.12974826147427), X322.5 = c(10.2039049079755,
9.57341805555556, 9.38568758716876, 9.13822159887798, 8.94393888888889,
8.79378581363004), X325 = c(9.86461042944785, 9.23893472222222,
9.05190516039052, 8.80583450210379, 8.61297777777778, 8.46346731571627
), X327.5 = c(9.5730490797546, 8.95366388888889, 8.76786750348675,
8.52597615708275, 8.33285972222222, 8.18865924895688), X330 = c(9.29567791411043,
8.67920416666667, 8.49494421199442, 8.25632117812062, 8.06634305555556,
7.92368984700974), X332.5 = c(9.0010981595092, 8.38594305555556,
8.20200139470014, 7.96879803646564, 7.78189166666667, 7.63967593880389
), X335 = c(8.71511349693252, 8.09972916666667, 7.92145885634589,
7.69297335203366, 7.50750694444444, 7.3643421418637), X337.5 = c(8.45265644171779,
7.84026666666667, 7.66316178521618, 7.43814305750351, 7.25333333333333,
7.11477607788595), X340 = c(8.19838036809816, 7.59187361111111,
7.41271827057183, 7.19209256661992, 7.00985416666667, 6.87590959666203
), X342.5 = c(7.95462883435583, 7.34913194444444, 7.17332914923291,
6.95607433380084, 6.77643055555556, 6.64161752433936), X345 = c(7.72929754601227,
7.12695138888889, 6.95060669456067, 6.7338920056101, 6.55681388888889,
6.42844089012517), X347.5 = c(7.50222699386503, 6.90189583333333,
6.72852022315202, 6.51498036465638, 6.33897916666667, 6.21110848400556
), X350 = c(7.2898527607362, 6.69248472222222, 6.52281171548117,
6.3138920056101, 6.13989722222222, 6.00979554937413), X352.5 = c(7.07927300613497,
6.48439166666667, 6.31443514644351, 6.10986956521739, 5.93754583333333,
5.81149652294854), X355 = c(6.86355214723926, 6.26889861111111,
6.09972524407252, 5.89783450210379, 5.72706527777778, 5.60363838664812
), X357.5 = c(6.6658527607362, 6.07161111111111, 5.90622873082287,
5.70649649368864, 5.53700833333333, 5.41251877607789), X360 = c(6.47400613496932,
5.88162777777778, 5.71633472803347, 5.5187713884993, 5.35024444444444,
5.22833796940195), X362.5 = c(6.30347852760736, 5.71433888888889,
5.54859414225942, 5.3527587657784, 5.1863375, 5.06425173852573
), X365 = c(6.16322699386503, 5.57911527777778, 5.41753835425384,
5.22367601683029, 5.05854027777778, 4.94001390820584), X367.5 = c(6.02653067484663,
5.44968333333333, 5.29124267782427, 5.10030294530154, 4.93744305555556,
4.82315020862309), X370 = c(5.86248466257669, 5.28735277777778,
5.12692747559275, 4.93981065918654, 4.77878055555556, 4.6638066759388
), X372.5 = c(5.68123006134969, 5.10715, 4.94811854951185,
4.764904628331, 4.60323333333333, 4.48933379694019), X375 = c(5.53815644171779,
4.96720416666667, 4.81097350069735, 4.62871388499299, 4.46926944444445,
4.35810987482615), X377.5 = c(5.40510429447853, 4.8370625,
4.68262761506276, 4.50320617110799, 4.34814444444444, 4.23741724617524
), X380 = c(5.30138343558282, 4.73901805555556, 4.5846889818689,
4.40751612903226, 4.25314444444444, 4.14589847009736), X382.5 = c(5.20306134969325,
4.64154722222222, 4.49053417015342, 4.31611079943899, 4.16125138888889,
4.05445757997218), X385 = c(5.07416871165644, 4.515375, 4.3646959553696,
4.19456802244039, 4.04227222222222, 3.93332127955494), X387.5 = c(4.96219325153374,
4.40868194444444, 4.25931520223152, 4.0922889200561, 3.9414,
3.83277607788595), X390 = c(4.83940797546012, 4.29276527777778,
4.14653974895398, 3.97920196353436, 3.82955277777778, 3.72600834492351
), X392.5 = c(4.71031288343558, 4.16622083333333, 4.02140446304045,
3.85572510518934, 3.70953194444445, 3.60538386648122), X395 = c(4.62059202453988,
4.07360138888889, 3.92935564853556, 3.76849228611501, 3.62277638888889,
3.51784283727399), X397.5 = c(4.49155521472393, 3.95385972222222,
3.81216178521618, 3.65344039270687, 3.50810833333333, 3.4116926286509
), X400 = c(4.37370858895706, 3.84129861111111, 3.70030125523013,
3.5432286115007, 3.39975277777778, 3.30254659248957), X402.5 = c(4.27044171779141,
3.738875, 3.59841562064156, 3.4434095371669, 3.30132638888889,
3.20369819193324), X405 = c(4.15562883435583, 3.6327375,
3.49318270571827, 3.33822159887798, 3.19675555555555, 3.10537273991655
), X407.5 = c(4.09877607361963, 3.57864305555556, 3.44027057182706,
3.28816129032258, 3.14875138888889, 3.05293602225313), X410 = c(4.01044785276074,
3.48679444444444, 3.35288842398884, 3.20463534361851, 3.06820833333333,
2.9671752433936), X412.5 = c(3.87490797546012, 3.35905694444444,
3.2244839609484, 3.07484291725105, 2.93775416666667, 2.8437983310153
), X415 = c(3.79108282208589, 3.28507361111111, 3.14952161785216,
3.00085273492286, 2.86421805555555, 2.77412378303199), X417.5 = c(3.68693558282209,
3.17824583333333, 3.04701394700139, 2.9043366058906, 2.76995972222222,
2.67318358831711), X420 = c(3.56437116564417, 3.05670972222222,
2.92747419804742, 2.786095371669, 2.65226666666667, 2.55702225312935
), X422.5 = c(3.51319018404908, 3.00990694444444, 2.87744769874477,
2.73367180925666, 2.60142361111111, 2.51227399165508), X425 = c(3.43132208588957,
2.92941805555555, 2.80041562064156, 2.65933099579243, 2.52816388888889,
2.43237969401947), X427.5 = c(3.31023926380368, 2.81629166666667,
2.68912831241283, 2.54957363253857, 2.41817777777778, 2.33177051460362
), X430 = c(3.26191717791411, 2.77505833333333, 2.64634030683403,
2.50681767180926, 2.37668055555556, 2.29549374130737), X432.5 = c(3.22984662576687,
2.74605555555556, 2.61894979079498, 2.48168022440393, 2.35282083333333,
2.26610987482615), X435 = c(3.13996932515337, 2.65807916666667,
2.5333179916318, 2.39782187938289, 2.26921388888889, 2.18432684283727
), X437.5 = c(3.08235582822086, 2.60515833333333, 2.4803249651325,
2.34626928471248, 2.21812083333333, 2.13608901251739), X440 = c(3.01686809815951,
2.54044583333333, 2.41671548117155, 2.2833842917251, 2.16062083333333,
2.07232267037552), X442.5 = c(2.93285889570552, 2.46135694444444,
2.33697489539749, 2.20531837307153, 2.08016805555556, 1.99902225312935
), X445 = c(2.8908773006135, 2.42607361111111, 2.30482426778243,
2.17530014025245, 2.04767916666667, 1.97140194714882), X447.5 = c(2.85198466257669,
2.38861111111111, 2.2694839609484, 2.14013884992987, 2.01676111111111,
1.93308901251738), X450 = c(2.8046472392638, 2.34394583333333,
2.22286750348675, 2.09689481065919, 1.97544444444445, 1.89651043115438
), X452.5 = c(2.77545705521472, 2.31733333333333, 2.20150627615063,
2.07733800841515, 1.95440277777778, 1.87571627260083), X455 = c(2.71198159509203,
2.26175277777778, 2.14609483960948, 2.02168022440393, 1.90238194444444,
1.82506536856745), X457.5 = c(2.69071779141104, 2.24759861111111,
2.1283709902371, 2.0067461430575, 1.88878055555556, 1.81217802503477
), X460 = c(2.63857055214724, 2.19480416666667, 2.07814365411437,
1.95862833099579, 1.84296111111111, 1.76875243393602), X462.5 = c(2.55233742331288,
2.10490416666667, 1.99411854951185, 1.87502664796634, 1.76141805555556,
1.68473435326843), X465 = c(2.54993251533742, 2.10804166666667,
1.99814644351464, 1.88111360448808, 1.76530277777778, 1.68772322670375
), X467.5 = c(2.54192944785276, 2.10937638888889, 1.99570990237099,
1.88144319775596, 1.76786666666667, 1.69657162726008), X470 = c(2.45424233128834,
2.02388472222222, 1.91476011157601, 1.80086255259467, 1.68827638888889,
1.61762865090403), X472.5 = c(2.38808588957055, 1.96169583333333,
1.85649232914923, 1.74286956521739, 1.63194444444444, 1.56048400556328
), X475 = c(2.40716871165644, 1.98333055555556, 1.8761589958159,
1.7647840112202, 1.65609861111111, 1.58707093184979), X477.5 = c(2.38796012269939,
1.96411527777778, 1.85740725244073, 1.74938990182328, 1.64029444444444,
1.57306258692629), X480 = c(2.32367484662577, 1.90594027777778,
1.80042677824268, 1.69331276297335, 1.58667777777778, 1.51872322670375
), X482.5 = c(2.26839877300614, 1.85602638888889, 1.75232914923291,
1.64626928471248, 1.542725, 1.47292350486787), X485 = c(2.24077914110429,
1.82308194444444, 1.72304323570432, 1.61980925666199, 1.5158,
1.44215159944367), X487.5 = c(2.19346625766871, 1.77742916666667,
1.67717712691771, 1.57596213183731, 1.46934861111111, 1.39640751043115
), X490 = c(2.1796226993865, 1.77528611111111, 1.67270432357043,
1.56773772791024, 1.46491111111111, 1.39967732962448), X492.5 = c(2.19796932515337,
1.79399861111111, 1.69254253835425, 1.58660028050491, 1.48578888888889,
1.42326842837274), X495 = c(2.16203067484663, 1.75784722222222,
1.66087866108787, 1.56017812061711, 1.45659583333333, 1.39502364394993
), X497.5 = c(2.12128220858896, 1.72433055555556, 1.62827615062762,
1.52875175315568, 1.42800833333333, 1.36483727399165), X500 = c(2.10455214723926,
1.71279027777778, 1.61463458856346, 1.51266058906031, 1.41571388888889,
1.35290403337969), X502.5 = c(2.09321779141104, 1.70464027777778,
1.60352022315202, 1.50263674614306, 1.40064722222222, 1.34636300417246
), X505 = c(2.06455828220859, 1.67302916666667, 1.57388145048815,
1.47552734922861, 1.37514166666667, 1.31759944367177), X507.5 = c(2.01607975460123,
1.62675138888889, 1.53272524407252, 1.43562692847125, 1.34284444444444,
1.27975660639777), X510 = c(1.97671165644172, 1.59260694444444,
1.50193444909344, 1.41013043478261, 1.31677916666667, 1.25430876216968
), X512.5 = c(1.96352147239264, 1.57798472222222, 1.48636262203626,
1.39764375876578, 1.30225555555556, 1.23669680111266), X515 = c(1.92503987730061,
1.54797083333333, 1.45469456066946, 1.36199298737728, 1.26766805555556,
1.21219749652295), X517.5 = c(1.90465030674847, 1.53300555555556,
1.44391352859135, 1.35238569424965, 1.2612375, 1.20831293463143
), X520 = c(1.87689570552147, 1.50217916666667, 1.4149330543933,
1.32729733520337, 1.23678194444445, 1.17577329624478), X522.5 = c(1.83759202453988,
1.46538888888889, 1.37917015341702, 1.29119775596073, 1.20174861111111,
1.14477607788595), X525 = c(1.83651533742331, 1.46525, 1.38037935843794,
1.29450490883591, 1.2079125, 1.15156189151599), X527.5 = c(1.82067791411043,
1.45758472222222, 1.36769874476987, 1.28326788218794, 1.19442916666667,
1.13923365785814), X530 = c(1.7854754601227, 1.42325833333333,
1.33740446304045, 1.25485553997195, 1.16439166666667, 1.11009457579972
), X532.5 = c(1.72706134969325, 1.36137083333333, 1.28353277545328,
1.20330014025245, 1.1164875, 1.05959248956885), X535 = c(1.73546012269939,
1.37703333333333, 1.2953570432357, 1.21220617110799, 1.12938333333333,
1.07361335187761), X537.5 = c(1.75189570552147, 1.39752083333333,
1.3135160390516, 1.23146283309958, 1.15030416666667, 1.10116133518776
), X540 = c(1.70230061349693, 1.35148888888889, 1.2665369595537,
1.18725666199158, 1.10636944444444, 1.06070792767733), X542.5 = c(1.71566564417178,
1.36359027777778, 1.28287029288703, 1.20369565217391, 1.1235375,
1.07357719054242), X545 = c(1.66589877300613, 1.31230416666667,
1.23633891213389, 1.15782889200561, 1.07775833333333, 1.01979972183588
), X547.5 = c(1.62098466257669, 1.27635555555556, 1.19730962343096,
1.11939270687237, 1.03757361111111, 0.990175243393602), X550 = c(1.64088650306749,
1.30173333333333, 1.22275592747559, 1.14718793828892, 1.06357916666667,
1.02470931849791), X552.5 = c(1.65776687116564, 1.31616944444444,
1.23976708507671, 1.16367180925666, 1.08286944444444, 1.03624200278164
), X555 = c(1.64775766871166, 1.30469861111111, 1.23003905160391,
1.15642496493689, 1.07983611111111, 1.02301529902643), X557.5 = c(1.57864417177914,
1.24234861111111, 1.16718131101813, 1.09518373071529, 1.01922638888889,
0.966821974965229), X560 = c(1.55608895705521, 1.22404166666667,
1.14994979079498, 1.07797896213184, 0.998729166666667, 0.953904033379694
), X562.5 = c(1.57327300613497, 1.24271111111111, 1.17039748953975,
1.10076437587658, 1.02429722222222, 0.982093184979138), X565 = c(1.54155828220859,
1.21247638888889, 1.14011994421199, 1.06987377279102, 0.995325,
0.950226703755216), X567.5 = c(1.5184754601227, 1.19163194444444,
1.11808926080893, 1.04673772791024, 0.969984722222222, 0.920390820584145
), X570 = c(1.52191104294479, 1.19953472222222, 1.12552022315202,
1.05369144460028, 0.979043055555555, 0.936059805285118),
X572.5 = c(1.49422699386503, 1.17113333333333, 1.09843793584379,
1.02884291725105, 0.956215277777778, 0.914119610570236),
X575 = c(1.48120552147239, 1.16091666666667, 1.08878382147838,
1.02371248246844, 0.950745833333333, 0.903524339360223),
X577.5 = c(1.49473312883436, 1.17405, 1.10468340306834, 1.04081346423562,
0.967102777777778, 0.918347705146036), X580 = c(1.45893558282209,
1.13822638888889, 1.07150488145049, 1.004904628331, 0.931488888888889,
0.888706536856745), X582.5 = c(1.40335889570552, 1.08981666666667,
1.02136262203626, 0.955345021037868, 0.882438888888889, 0.842457579972184
), X585 = c(1.41981901840491, 1.11120277777778, 1.04046164574617,
0.976112201963534, 0.902045833333333, 0.854774687065369),
X587.5 = c(1.44122085889571, 1.13389722222222, 1.06531938633194,
0.998193548387097, 0.927052777777778, 0.884666203059805),
X590 = c(1.43262883435583, 1.12188472222222, 1.05589539748954,
0.991642356241234, 0.923915277777778, 0.883214186369958),
X592.5 = c(1.39457668711656, 1.08495694444444, 1.01676150627615,
0.954368863955119, 0.886066666666667, 0.842401947148818),
X595 = c(1.39473006134969, 1.09030138888889, 1.02193584379358,
0.95813744740533, 0.889866666666667, 0.851438108484006),
X597.5 = c(1.39176380368098, 1.08874305555556, 1.02160251046025,
0.960784011220196, 0.891755555555556, 0.851367176634214),
X600 = c(1.32321472392638, 1.02342361111111, 0.958054393305439,
0.896713884992987, 0.828456944444444, 0.789112656467316),
X602.5 = c(1.3699754601227, 1.06539861111111, 1.00389818688982,
0.94194950911641, 0.875038888888889, 0.832920723226704),
X605 = c(1.39004294478528, 1.0856125, 1.02410460251046, 0.964893408134642,
0.897881944444444, 0.851397774687065), X607.5 = c(1.33887423312883,
1.04344305555556, 0.978672245467225, 0.918176718092567, 0.853443055555556,
0.810876216968011), X610 = c(1.34292944785276, 1.04911111111111,
0.98465690376569, 0.922030855539972, 0.858780555555556, 0.820618915159944
), X612.5 = c(1.32123006134969, 1.02857083333333, 0.962319386331939,
0.899249649368864, 0.834901388888889, 0.797037552155772),
X615 = c(1.30576380368098, 1.01544166666667, 0.949560669456067,
0.889232819074334, 0.824005555555556, 0.787675938803894),
X617.5 = c(1.30801840490798, 1.01950138888889, 0.959458856345886,
0.902255259467041, 0.839116666666667, 0.80459388038943),
X620 = c(1.25273619631902, 0.963565277777778, 0.903634588563459,
0.845955119214586, 0.781859722222222, 0.751739916550765),
X622.5 = c(1.24233742331288, 0.951993055555556, 0.889652719665272,
0.832720897615708, 0.765165277777778, 0.728485396383866),
X625 = c(1.3115736196319, 1.020975, 0.960577405857741, 0.902300140252454,
0.835329166666667, 0.789098748261474), X627.5 = c(1.32251840490798,
1.03869861111111, 0.977846582984658, 0.916507713884993, 0.852429166666667,
0.812655076495132), X630 = c(1.26833435582822, 0.9928125,
0.93086750348675, 0.87539270687237, 0.812751388888889, 0.775739916550765
), X632.5 = c(1.24898773006135, 0.965934722222222, 0.908059972105997,
0.85682889200561, 0.794722222222222, 0.751435326842837),
X635 = c(1.28299386503067, 0.995876388888889, 0.936375174337517,
0.881263674614306, 0.819331944444444, 0.78326842837274),
X637.5 = c(1.2784018404908, 1.00060833333333, 0.939645746164575,
0.880981767180926, 0.821463888888889, 0.792333796940195),
X640 = c(1.24037116564417, 0.960616666666667, 0.905357043235704,
0.846816269284712, 0.787144444444444, 0.744055632823366),
X642.5 = c(1.19373619631902, 0.907856944444444, 0.852075313807531,
0.797594670406732, 0.732779166666667, 0.684244784422809),
X645 = c(1.17663190184049, 0.898422222222222, 0.835518828451883,
0.782708274894811, 0.717233333333333, 0.684310152990264),
X647.5 = c(1.21073619631902, 0.943138888888889, 0.879875871687587,
0.826015427769986, 0.7630125, 0.737840055632823), X650 = c(1.20088036809816,
0.934829166666667, 0.877008368200837, 0.821608695652174,
0.760254166666667, 0.727004172461752), X652.5 = c(1.18600920245399,
0.915881944444444, 0.860887029288703, 0.80358064516129, 0.744027777777778,
0.705867872044506), X655 = c(1.22061349693252, 0.951930555555556,
0.896224546722455, 0.840730715287518, 0.784806944444444,
0.750878998609179), X657.5 = c(1.19243865030675, 0.924801388888889,
0.865479776847978, 0.81258064516129, 0.757759722222222, 0.721283727399165
), X660 = c(1.10550920245399, 0.841702777777778, 0.780730822873082,
0.731366058906031, 0.673393055555556, 0.638547983310153)), row.names = c(NA,
6L), class = "data.frame")
My code:
Data <- data.frame(Data)
library(rgl)
library(pls)
x <- as.POSIXct(Data$Date, format = "2013-01-10", tz = "Australia/Adelaide")
y <- Data$Wavelength
z <- as.matrix(Data[,3:167])
open3d()
plot3d(x, y, z,col="purple", size=3, xlab = "Date", ylab = "Wavelength", zlab = "Absorbance (/cm)")
I get a not very nice plot as shown in the second graph.
The x-axis has labels in numerical dates, but I want the actual dates in the format like "1 June 2013" or "1/6/2013".
I also don't know how to make a nice rainbow colour looking 3D graph.
Any help is welcome :)
a typical UV-Vis spectrum looks like graph 3 below
using the codes provided by Marco Sandri,
library(tidyr)
library(ggplot2)
library(plotly)
Data %>%
gather(Series, y, X250:X660, factor_key=TRUE) %>%
plot_ly(x = ~Date, y = ~Wavelength, z = ~y,
type = 'scatter3d', mode = 'lines', color = ~Series)
The graph 4 is the plot I get.
A solution based on the plotly package:
library(tidyr)
library(plotly)
Data %>%
gather(Series, y, X250:X660, factor_key=TRUE) %>%
plot_ly(x = ~Date, y = ~Wavelength, z = ~y, type = 'scatter3d', mode = 'lines', color = ~Series)
You may omit and redraw the axes using bbox3d. In bbox3d just xat= and xlab= specifications are needed, where we use x.
open3d()
plot3d(x, y, z, col="purple", size=3, xlab="Date", ylab="Wavelength",
zlab="Absorbance (/cm)", axes=FALSE, top=TRUE)
bbox3d(xat=x, xlab=x, col="black", front="line", back="line", lit=FALSE)

Radar chart is not displaying the values accurately on the axis

I am trying to create a radar chart but the axis stops at 4 when the maximum I have given is 10. Any help is much appreciated.
I have taken a subset of the dataset from a .csv file. Below is the subset
datasample = structure(list(Score = 7.522, Whisker.high = 7.581728, Whisker.low = 7.462272,
GDP = 1.482383, Family = 1.551122, Health = 0.7925655, Freedom = 0.6260067,
Generosity = 0.3552805, TrustInGovernmentAndCorruption. = 0.4007701,
Dystopia.Residual = 2.3137), .Names = c("Score", "Whisker.high",
"Whisker.low", "GDP", "Family", "Health", "Freedom", "Generosity",
"TrustInGovernmentAndCorruption.",
"Dystopia.Residual"), class = "data.frame", row.names = c(NA,
-1L))
The subset contains 10 columns and 1 row.
Code:
library(fmsb)
#data <- read.csv("~/Desktop/App-1/2017.csv")
#datasample <- data[2, 3:12]
datasample <- rbind(rep(10,12), rep(0,12), datasample)
radarchart(datasample, axistype = 1,
pcol = rgb(0.2,0.5,0.5,0.9), pfcol = rgb(0.2,0.5,0.5, 0.5), plwd = 4,
cglcol = "grey", cglty = 1, axislabcol = "grey",caxislabels = seq(0,20,1), cglwd = 0.8,
vlcex = 0.8)
Here is the chart created:
The highest value in the subset (datasample) is 7.581728 but the chart does not display that value. How do I fix this?
The radar plot you are generating has an axis that is percentages of the max data point (you can see these when you remove the caxislabels from your plot (you'll get 100%,75%,50%,25%). The values you are seeing around 3 are actually the ~7.5 values (on the 75% grid line).
One way to fix this so that the axis is as expected:
radarchart(datasample, axistype = 1,
pcol = rgb(0.2,0.5,0.5,0.9), pfcol = rgb(0.2,0.5,0.5, 0.5), plwd = 4,
cglcol = "grey", cglty = 1, axislabcol = "grey",
caxislabels = seq(min(datasample),max(datasample),1), seg=length(seq(min(datasample),max(datasample),1))-1,
cglwd = 0.8, vlcex = 0.8)

Resources