I am new to R and trying to draw a boxplot on two factors. I am able to draw a graph according to my requirement. Here is the code:
library(ggplot2)
Systems <- c(rep("A", 23), rep("B", 328), rep("C", 85), rep("D", 25))
treatment <- rep(c("MEAN\n0.035 0.252 0.005 0.032", "MEAN\n0.030 0.213 0.008 0.033"), each = 461)
Performance <- c(
0.041817315, 0.012366105, 0.008223291, 0.101194094, 0.032095414, 0.022424856, 0.004272651, 0.02568757, 0.012011461, 0.032519093, 0.015862062, 0.027747871, 0.024599762, 0.003786862, 0.28017758, 0.017898477, 0.00646475, 0.004093185, 0.000740573, 0.039312335, 0.002415459, 0.051774672, 0.029394015, 0.303119908, 0.247602112, 0.234497662, 0.240247293, 0.256006375, 0.241818886, 0.241818886, 0.23355839, 0.23355401, 0.24791564, 0.232738515, 0.247145881, 0.234726096, 0.233802269, 0.296144867, 0.318978078, 0.309485102, 0.24498581, 0.361880846, 0.233798292, 0.233802269, 0.23446443, 0.23446443, 0.245941147, 0.251454016, 0.256166292, 0.269703778, 0.25459034, 0.255547875, 0.293828554, 0.269443031, 0.245104749, 0.278098811, 0.304266148, 0.238588328, 0.304754431, 0.251716996, 0.260886932, 0.260633422, 0.247319476, 0.24162866, 0.268908914, 0.23960451, 0.255093289, 0.268908914, 0.245971624, 0.26665091, 0.279822691, 0.268784457, 0.298624598, 0.241807867, 0.232050361, 0.241527075, 0.27750843, 0.26665091, 0.2317304, 0.234567279, 0.232487121, 0.233076363, 0.242322263, 0.241818886, 0.241818886, 0.235521394, 0.261765062, 0.270101105, 0.242477399, 0.232661245, 0.283295967, 0.247602112, 0.263427876, 0.239485768, 0.237005999, 0.243690789, 0.247371437, 0.237005999, 0.247231137, 0.249111033, 0.26665091, 0.254097987, 0.273745634, 0.290167407, 0.245623389, 0.241930972, 0.231602752, 0.234514088, 0.256039044, 0.265463913, 0.256166292, 0.247743609, 0.232694788, 0.237961675, 0.281536336, 0.24977717, 0.262282857, 0.24543148, 0.247155404, 0.247155404, 0.26129785, 0.234514088, 0.26494978, 0.258628847, 0.257580217, 0.253061784, 0.232630126, 0.247155404, 0.244319159, 0.262394668, 0.26665091, 0.3165875, 0.268706383, 0.250278577, 0.253011248, 0.249419117, 0.245104749, 0.235595377, 0.238554589, 0.273267375, 0.248984622, 0.24520136, 0.258955737, 0.2317304, 0.272465904, 0.23870662, 0.248026932, 0.263427876, 0.278497558, 0.265828268, 0.234826045, 0.2317304, 0.232172596, 0.235692813, 0.232737079, 0.297579932, 0.286422023, 0.259325175, 0.250639446, 0.231587836, 0.300662192, 0.248210353, 0.294150342, 0.251203475, 0.251417668, 0.295233578, 0.256006375, 0.256006375, 0.245015073, 0.249356914, 0.293528269, 0.281821725, 0.248799266, 0.301499956, 0.247721985, 0.290792643, 0.328679821, 0.330321343, 0.30640335, 0.276763556, 0.247496304, 0.237458207, 0.237458207, 0.237516949, 0.233802269, 0.234468703, 0.239264575, 0.234887381, 0.23446443, 0.234887381, 0.234225205, 0.237004685, 0.23455164, 0.23446443, 0.234870008, 0.232694788, 0.234870008, 0.234860348, 0.270044052, 0.232694788, 0.269666687, 0.236614177, 0.280480722, 0.243978724, 0.249111033, 0.279925672, 0.232172596, 0.239249363, 0.272197191, 0.246987548, 0.244882001, 0.269280706, 0.249566945, 0.241863369, 0.239677242, 0.242426616, 0.253140755, 0.239869221, 0.239677242, 0.23171238, 0.275635746, 0.231602752, 0.286266232, 0.259265885, 0.239869221, 0.236614177, 0.255256967, 0.257580217, 0.290128013, 0.274832429, 0.243149974, 0.232123048, 0.235250227, 0.276830805, 0.231188689, 0.247743609, 0.245963204, 0.259455641, 0.32522266, 0.252770086, 0.236461595, 0.244470967, 0.244024628, 0.24498581, 0.2317304, 0.233464424, 0.266062106, 0.233118162, 0.243588113, 0.232694788, 0.243435021, 0.249775037, 0.240018899, 0.26665091, 0.26665091, 0.268784457, 0.237497376,
0.237483089, 0.237145874, 0.237145874, 0.2317304, 0.243435021, 0.269419291, 0.243767405, 0.274193607, 0.243435021, 0.237281364, 0.237205977, 0.237145874, 0.237145874, 0.245029635, 0.242611375, 0.237961675, 0.266369762, 0.266369762, 0.245760558, 0.266369762, 0.249121027, 0.291800661, 0.240954111, 0.238391917, 0.235264993, 0.233355127, 0.234898357, 0.235244609, 0.238499482, 0.234215035, 0.236608826, 0.235265733, 0.25019165, 0.283415889, 0.237145874, 0.267352731, 0.237422834, 0.273147585, 0.225775832, 0.238321926, 0.235125859, 0.232694788, 0.249626478, 0.234218629, 0.235269307, 0.26533449, 0.242207321, 0.24183494, 0.241848474, 0.256006375, 0.24183494, 0.241848474, 0.2734133, 0.241848474, 0.241848474, 0.24183494, 0.23422781, 0.248608779, 0.235125859, 0.234871225, 0.235125859, 0.233774363, 0.235278439, 0.245684423, 0.234705022, 0.245684423, 0.235186554, 0.245684423, 0.23470016, 0.236614177, 0.245953538, 0.245953538, 0.245922432, 0.249522459, 0.276680994, 0.251743401, 0.235125859, 0.222236695, 0.251487861, 0.286975357, 0.240545386, 0.245488295, 0.233464424, 0.270731686, 0.241818886, 0.285677834, 0.24543148, 0.237961675, 0.262911409, 0.258234963, 0.24326508, 0.236608826, 0.237516949, 0.26533449, 0.003208185, 0.003075313, 0.003075313, 0.051965266, 0.086809801, 0.002074263, 0.003814715, 0.00241056, 0.004519913, 0.002354925, 0.003668154, 0.002411354, 0.001046015, 0.00641338, 0.002344457, 0.00090009, 0.010972388, 0.001492537, 0.00084317, 0.005872887, 0.003912383, 0.001643901, 0.001492537, 0.001844077, 0.00084317, 0.005379174, 0.001821256, 0.002505201, 0.001051525, 0.00084317, 0.002505201, 0.004837974, 0.00084317, 0.002488134, 0.005078271, 0.00084317, 0.002488134, 0.00250647, 0.00250647, 0.002480833, 0.002480833, 0.001101322, 0.010244482, 0.001321974, 0.012283591, 0.001733435, 0.001512552, 0.001671509, 0.001428863, 0.002618663, 0.005121464, 0.002808259, 0.002503417, 0.002558745, 0.00216939, 0.002021331, 0.001588465, 0.001690088, 0.003279291, 0.002295707, 0.003248547, 0.021351276, 0.002499903, 0.002503417, 0.001101322, 0.00354847, 0.002499903, 0.003075313, 0.00567605, 0.01320935, 0.001052632, 0.004384033, 0.001918676, 0.001597092, 0.015212658, 0.001046015, 0.006676165, 0.006883556, 0.002696254, 0.003247508, 0.002709837, 0.002234992, 0.011494253, 0.001311413, 0.014849595, 0.012022537, 0.006497906, 0.025349246, 0.020579744, 0.049220779, 0.018911298, 0.005464481, 0.023748064, 0.045756258, 0.010638298, 0.019893403, 0.023962608, 0.05465644, 0.028966333, 0.004459272, 0.105586592, 0.075615135, 0.022154774, 0.017105029, 0.005208333, 0.011363636, 0.008951424, 0.117416075, 0.007916667, 0.078388988, 0.030861112, 0.003519782, 0.005422482, 0.125796873, 0.005031371, 0.03362749, 0.000778961, 0.016681028, 0.004599127, 0.000454307, 0.001505359, 0.031611448, 0.011308386, 0.002134792, 0.286294212, 0.018161072, 0.006453087, 0.003571249, 0.000447235, 0.042566651, 7.77303E-05, 0.042401148, 0.023784287, 0.245226355, 0.207228787, 0.204169525, 0.211077481, 0.213258479, 0.207484024, 0.207484024, 0.201602486, 0.202638497, 0.216700318, 0.201214614, 0.220748161, 0.202433079, 0.201738383, 0.248574743, 0.262874666,
0.252606723, 0.200504039, 0.312541501, 0.202773831, 0.201738383, 0.2030333, 0.2030333, 0.203064156, 0.209310089, 0.217450641, 0.231772732, 0.209757897, 0.217977319, 0.247090075, 0.21844954, 0.209559111, 0.225575484, 0.254032564, 0.201524647, 0.24778379, 0.217517211, 0.222981128, 0.227145657, 0.210758647, 0.208297414, 0.216762142, 0.203586766, 0.216700206, 0.216762142, 0.207592071, 0.213666768, 0.227338434, 0.215879786, 0.246166402, 0.20561442, 0.205026788, 0.207675824, 0.227655498, 0.213666768, 0.197325754, 0.210254948, 0.206766076, 0.207358384, 0.218678788, 0.207484024, 0.207484024, 0.204014221, 0.218887554, 0.225205822, 0.204384584, 0.198406675, 0.227971421, 0.207228787, 0.214348845, 0.201777676, 0.205916468, 0.213450757, 0.209587709, 0.205916468, 0.209362242, 0.20856388, 0.213666768, 0.216186368, 0.234453313, 0.248382745, 0.21701993, 0.213600036, 0.201106069, 0.203802471, 0.216655494, 0.225560499, 0.217450641, 0.208587224, 0.197681539, 0.199276425, 0.232171602, 0.210470295, 0.22175041, 0.204355918, 0.204475181, 0.204475181, 0.231548299, 0.203802471, 0.223041945, 0.217862851, 0.230785952, 0.213283262, 0.200257172, 0.204475181, 0.202897929, 0.211315524, 0.213666768, 0.263361407, 0.225185308, 0.214271007, 0.210497889, 0.212978687, 0.209559111, 0.199014939, 0.20945405, 0.224553068, 0.217749634, 0.216496692, 0.212296213, 0.197325754, 0.221826528, 0.208655636, 0.20192612, 0.214348845, 0.223101747, 0.23194135, 0.198683705, 0.197325754, 0.198089791, 0.20427291, 0.199290161, 0.24070988, 0.249032587, 0.218488173, 0.211126674, 0.197780282, 0.244029201, 0.208767987, 0.240834568, 0.209095817, 0.20977662, 0.239262653, 0.213258479, 0.213258479, 0.209840866, 0.210998294, 0.251844378, 0.22782243, 0.209390413, 0.242168553, 0.207556718, 0.230220324, 0.277619451, 0.271500416, 0.2463793, 0.236268228, 0.204252778, 0.205975522, 0.205975522, 0.20638888, 0.201738383, 0.202307262, 0.203126957, 0.203547468, 0.2030333, 0.203547468, 0.202251975, 0.206942541, 0.202009011, 0.2030333, 0.199306658, 0.197681539, 0.199306658, 0.200035605, 0.219731274, 0.197681539, 0.220112984, 0.201326042, 0.222447694, 0.204767129, 0.20856388, 0.238296852, 0.198089791, 0.20783083, 0.228566801, 0.213406582, 0.202128774, 0.223103043, 0.21174389, 0.209480203, 0.203141599, 0.213522888, 0.218265827, 0.203332504, 0.203141599, 0.200857909, 0.221504103, 0.201106069, 0.234932916, 0.224156158, 0.203332504, 0.201326042, 0.212033061, 0.230785952, 0.232169974, 0.22103837, 0.208472924, 0.201662359,
0.197770095, 0.227186459, 0.197226949, 0.208587224, 0.203044091, 0.21799408, 0.27616292, 0.206754881, 0.205386431, 0.20518108, 0.206706255, 0.200504039, 0.197325754, 0.201725618, 0.216929898, 0.198194632, 0.210965099, 0.197681539, 0.210099248, 0.205271974, 0.200638561, 0.213666768, 0.213666768, 0.215879786, 0.209006585, 0.208696114, 0.207817635, 0.207817635, 0.197325754, 0.210099248, 0.216982956, 0.212178741, 0.217721009, 0.210099248, 0.20711904, 0.208521315, 0.207817635, 0.207817635, 0.205501252, 0.202278423, 0.199276425, 0.213447242, 0.213447242, 0.205132583, 0.213447242, 0.214546613, 0.233837102, 0.20461375, 0.200041017, 0.203376022, 0.201666622, 0.203273295, 0.206239566, 0.206005147, 0.202367361, 0.205336165, 0.206159599, 0.212043546, 0.23652672, 0.207817635, 0.222323542, 0.207992955, 0.230179094, 0.191639063, 0.203652472, 0.205707127, 0.197681539, 0.210851357, 0.20206244, 0.205851609, 0.230072742, 0.203700261, 0.204112552, 0.203387156, 0.213258479, 0.204112552, 0.203387156, 0.226895739, 0.203387156, 0.203387156, 0.204112552, 0.202062597, 0.207156386, 0.205707127, 0.204103383, 0.205707127, 0.20231351, 0.205851767, 0.202278126, 0.203456946, 0.202278126, 0.206408028, 0.202278126, 0.202940706, 0.201326042, 0.205811807, 0.205811807, 0.202945571, 0.209642676, 0.236595043, 0.211389397, 0.205707127, 0.187165901, 0.221709686, 0.235580538, 0.205130035, 0.208843627, 0.201725618, 0.228112266, 0.207484024, 0.233405455, 0.204355918, 0.199276425, 0.2214728, 0.214289366, 0.207335809, 0.205336165, 0.20638888, 0.230072742, 0.011415222, 0.003524363, 0.003524363, 0.065250462, 0.099337796, 0.002467596, 0.005194761, 0.002749848, 0.00431973, 0.002470309, 0.00429052, 0.002528805, 0.000964973, 0.007359328, 0.002605198, 0.010989011, 0.012864128, 0.001187648, 0.003546099, 0.024859586, 0.004188306, 0.002222601, 0.001187648, 0.002754248, 0.003546099, 0.001364, 0.001148428, 0.002092947, 0.000649351, 0.003546099, 0.002092947, 0.002955342, 0.003546099, 0.012749845, 0.002594875, 0.003546099, 0.012749845, 0.002994309, 0.002994309, 0.021827371, 0.021827371, 0.001730104, 0.011329362, 0.001260936, 0.01263916, 0.001845543, 0.002035106, 0.003043491, 0.002160411, 0.001939528, 0.010275639, 0.003682458, 0.002439817, 0.012294413, 0.003980996, 0.028844157, 0.002571735, 0.005293216, 0.003654834, 0.002891218, 0.002046854, 0.037579121, 0.002432344, 0.002439817, 0.001730104, 0.006082265, 0.002432344, 0.003524363, 0.006134648, 0.009195465, 0.000657895, 0.005597993, 0.002345224, 0.001933761, 0.0150357, 0.000964973, 0.004387928, 0.00773195, 0.002727137, 0.006166549, 0.002631304, 0.002269814, 0.000711744, 0.001519004, 0.013924241, 0.016998883, 0.004487617, 0.009501123, 0.06314105, 0.00686984, 0.016491278, 0.005154639, 0.006493982, 0.028453674, 0.005319149, 0.165847332, 0.015483992, 0.151746052, 0.058287127, 0.004457018, 0.005368773, 0.037517336, 0.012809372, 0.012127533, 0.002079002, 0.003448276, 0.017034111, 0.117145251, 0.016396803, 0.092959905
)
data <- data.frame(Systems, treatment, Performance)
data$Systems <- factor(data$Systems, levels = c("A", "B", "C", "D"))
colors <- c(rep("#222222", 23), rep("#777777", 328), rep("#AAAAAA", 85), rep("#CCCCCC", 25), rep("#222222", 23), rep("#777777", 328), rep("#AAAAAA", 85), rep("#CCCCCC", 25))
scaleFUN <- function(x) sprintf("%.3f", x)
ggplot(data, aes(x = Systems, y = Performance, fill = treatment)) +
geom_boxplot(alpha = 1, aes(fill = factor(colors))) +
facet_wrap(~ treatment) +
stat_summary(
fun.y = mean, geom = "point", shape = 21, size = 5, color = "#FFFFFF", fill = "#222222"
) +
ylab("Average Precision") +
ggtitle(" TEC-Gensim TEC-Matlab") +
theme(
legend.position = "none",
panel.grid.major = element_line(colour = "#d3d3d3"),
panel.border = element_blank(),
panel.background = element_blank(),
plot.title = element_text(size = 14, face = "bold", hjust = 0.5)
) +
scale_fill_brewer(palette = "Greys") +
coord_cartesian(ylim = c(0.001, 0.3)) +
scale_y_continuous(breaks = c(0, 0.002, 0.004, 0.008, 0.016, 0.032, 0.064, 0.128, 0.256))
Such transformation making the display better but disturbing the mean value manifested through geom-point using stat_summary.
Maybe you are looking for the geom = "label" option inside stat_summary?
library(ggplot2)
Systems <- c(rep("A", 23), rep("B", 328), rep("C", 85), rep("D", 25))
treatment <- rep(c("TEC-Gensim", "TEC-Matlab"), each = 461)
Performance <- c(rnorm(n = 230, mean = 0.035, sd = 0.02),
rnorm(n = 231, mean = 0.252, sd = 0.01),
rnorm(n = 230, mean = 0.005, sd = 0.03),
rnorm(n = 231, mean = 0.031, sd = 0.01))
Performance <- c(runif(n = 230, max = 0.3),
runif(n = 231, max = 0.3),
runif(n = 230, max = 0.3),
runif(n = 231, max = 0.3))
data <- data.frame(Systems, treatment, Performance)
data$Systems <- factor(data$Systems, levels = c("A", "B", "C", "D"))
colors <- c(rep("#222222", 23), rep("#777777", 328), rep("#AAAAAA", 85), rep("#CCCCCC", 25), rep("#222222", 23), rep("#777777", 328), rep("#AAAAAA", 85), rep("#CCCCCC", 25))
scaleFUN <- function(x) sprintf("%.3f", x)
ggplot(data, aes(x = Systems, y = Performance, fill = treatment)) +
geom_boxplot(alpha = 1, aes(fill = factor(colors))) +
facet_wrap(~ treatment) +
stat_summary(fun.y = mean, geom = "point", shape = 21, size = 5,
color = "#FFFFFF", fill = "#222222") +
stat_summary(fun.y = mean, geom = "label", aes(label = round(..y.., 3)),
hjust = -0.3, fill = 'white') +
ylab("Average Precision") +
theme(
legend.position = "none",
panel.grid.major = element_line(colour = "#d3d3d3"),
panel.border = element_blank(),
panel.background = element_blank(),
plot.title = element_text(size = 14, face = "bold", hjust = 0.5)
) +
scale_fill_brewer(palette = "Greys") +
coord_cartesian(ylim = c(0.001, 0.3)) +
scale_y_continuous(breaks = c(0, 0.002, 0.004, 0.008, 0.016, 0.032, 0.064, 0.128, 0.256))
```
Related
I am trying to make a problem more reactive to new inputs here is where the error is given
Pwh_Design=reactive((input$Pwh+0.2*(input$Pso-input$Pwh)))
Gtd=Pwh_Design-P_operating_point_formation/(0-D_operating_point)
this is in the server.
the entire app:
UI:
library(shiny)
# Define UI for application that draws a histogram
shinyUI(fluidPage(
# Application title
titlePanel("OTIS Gas Lift"),
fluidRow(column(width = 6,
numericInput(inputId = "Dmax",label = "Depth to mid perforation",value = 7500),
numericInput("Pwh","Pwh",100),
numericInput("Tres","Tres",182),
numericInput("Pso","P Casing at Surface",870),
numericInput("Psc","P Casing at Depth D1",1050),
numericInput("D1","D1",7000),
numericInput("P_across_valve","P_across_valve",100),
numericInput("GL","Load Grad",0.5),
numericInput("Pwf","Pwf",1760),
numericInput("RGOR","Required GOR",400)
),
column(width = 6,
numericInput("FGOR","Formation GOR",200),
numericInput("Twh","Twh",100),
numericInput("Pko","kill pressure at Surface",920),
numericInput("Pk","Kill Pressure at D2",1100),
numericInput("D2","D2",7000),
numericInput("T_inj","T_inj",100),
numericInput("q","Desired Production Rate STB/d",600),
numericInput("R","R",0.1534),
numericInput("Gf","Flowing Grad before inj",0.4)
)),
fluidRow(submitButton(text = "Apply Changes",width = "100%")),
splitLayout(tableOutput(outputId = "table"),plotOutput(outputId = "plot"))))
'''
This is the server
library(shiny)
shinyServer(function(input, output) {
Dmax=reactiveValues() #to mid perforation ft
#one of those two next must be given
FGOR=reactiveValues() #scf/STB Formation GOR
Pwh=reactiveValues() #psig
Twh=reactiveValues() #degree fahrenheit
Tres=reactiveValues() #degree fahrenheit
#casing and kill gradients
Pso=reactiveValues() #psig
Pcs=reactiveValues() #psig at 7000ft
D1=reactiveValues() #ft
Pko=reactiveValues() #psig
Pk=reactiveValues() #psig at 7000ft
D2=reactiveValues() #ft
P_across_valve=reactiveValues() #psig
T_inj=reactiveValues() #degree fahrenheit
GL=reactiveValues() #load gradient (kill fluid grad)
q=reactiveValues()
Pwf=reactiveValues() #psi or BHP
RGOR=reactiveValues() #scf/STB required GOR
R=reactiveValues()
Gf=reactiveValues() #flowing gradient before injection default value
library(ggplot2)
library(dplyr)
#plot basics
plot<-reactive(ggplot+
coord_cartesian(xlim = c(0,input$Pwf+500))+
scale_y_continuous(trans = "reverse")+
scale_x_continuous(position = "top"))
#Flowing Gradient
#slope Gf
#point (pwf,Dmax)
#get p1 at depth 4000ft
p1=reactive(input$Pwf-input$Gf*(input$Dmax-4000))
flowing_gradient<-reactive(data.frame(D=c(4000,input$Dmax),P=c(p1,input$Pwf)))
plot0<-plot+
geom_point(data = flowing_gradient,aes(x=P,y=D))+
geom_line(data = flowing_gradient,aes(x=P,y=D))
#casing gradient
casing_gradient<-reactive(data.frame(D=c(0,input$D1),P=c(input$Pso,input$Pcs)))
plot1<-plot0+geom_point(data=casing_gradient,aes(x=P,y=D))+
geom_line(data=casing_gradient,aes(x=P,y=D))
Gc=reactive((input$Pso-input$Pcs)/(0-input$D1))
#killing gradient
killing_gradient<-reactive(data.frame(D=c(0,input$D2),P=c(input$Pko,input$Pk)))
plot2<-plot1+geom_point(data=killing_gradient,aes(x=P,y=D))+
geom_line(data=killing_gradient,aes(x=P,y=D))
Gk=reactive((input$Pko-input$Pk)/(0-input$D2))
#balance point
d1=reactive((input$Pwf-input$Pso-input$Gf*input$Dmax)/(Gc-input$Gf))
d_balance_point=d1
#operating_point
d1=reactive((input$Pso-input$Pwf+input$Gf*input$Dmax-input$P_across_valve)/(input$Gf-Gc))
D_operating_point=d1
P_operating_point_casing=reactive(input$Pso+D_operating_point*Gc)
P_operating_point_formation=reactive(input$Pwf-input$Gf*(input$Dmax-D_operating_point))
plot3<-plot2+geom_point(aes(x=P_operating_point_formation,y=D_operating_point))
#Tubing grad
tubing_grad<-reactive(data.frame(D=c(0,D_operating_point),P=c(input$Pwh,P_operating_point_formation)))
plot4<-plot3+geom_point(data = tubing_grad,aes(x=P,y=D))+
geom_line(data = tubing_grad,aes(x=P,y=D))
#Tubing_design_grad
Pwh_Design=reactive((input$Pwh+0.2*(input$Pso-input$Pwh)))
Gtd=Pwh_Design-P_operating_point_formation/(0-D_operating_point) #Tubing design grad
tubing_design_grad<-data.frame(D=c(0,D_operating_point),P=c(Pwh_Design,P_operating_point_formation))
plot5<-plot4+geom_point(data = tubing_design_grad,aes(x=P,y=D))+
geom_line(data = tubing_design_grad,aes(x=P,y=D))
#first valve
D_valve1=reactive((input$Pwh-input$Pko)/(Gk-input$GL))
PK_valve1=reactive(D_valve1*Gk+input$Pko)
PTD_valve1=Gtd*D_valve1+Pwh_Design
df<-reactive(data.frame(D=c(0,D_valve1),P=c(input$Pwh,PK_valve1)))
#ploting
plot6<-plot5+geom_point(data = df, aes(x=P,y=D))+
geom_line(data = df, aes(x=P,y=D))
df<-data.frame(D=c(D_valve1,D_valve1),P=c(PTD_valve1,PK_valve1))
plot7<-plot6+geom_point(data = df, aes(x=P,y=D))+
geom_line(data = df, aes(x=P,y=D))
plot<-plot7
Final_table<-data.frame(depth=D_valve1,
Pc=PK_valve1,
Pt=PTD_valve1)
dvalve=D_valve1
PTDvalve=PTD_valve1
Pcvalve=PK_valve1
D_valve=D_valve1
PTD_valve=PTD_valve1
while (dvalve<D_operating_point) {
dvalve=reactive((PTDvalve-input$Pso-dvalve*input$GL)/(Gc-input$GL))
Pcvalve=reactive(input$Pso+Gc*dvalve)
if(dvalve<D_operating_point){
df<-data.frame(D=c(D_valve,dvalve),P=c(PTD_valve,Pcvalve))
plot<-plot+geom_point(data = df, aes(x=P,y=D))+
geom_line(data = df, aes(x=P,y=D))
PTDvalve=Gtd*dvalve+Pwh_Design
df<-data.frame(D=c(dvalve,dvalve),P=c(PTDvalve,Pcvalve))
plot<-plot+geom_point(data = df, aes(x=P,y=D))+
geom_line(data = df, aes(x=P,y=D))
valve<-c(dvalve,Pcvalve,PTDvalve)
Final_table<-rbind(Final_table,valve)
D_valve=dvalve
PTD_valve=PTDvalve
}}
output$plot<-renderPlot(plot)
valve<-c(D_operating_point,P_operating_point_casing,P_operating_point_formation)
Final_table<-rbind(Final_table,valve)
GTemp=reactive((input$Tres-input$Twh)/input$Dmax)
CT_data<-data.frame(Temp=c(61:300),Ct=c(0.998,0.996,0.994,0.991,0.989,0.987,0.985,0.983,0.981,0.979,0.977,0.975,0.973,0.971,0.969,0.967,0.965,0.963,0.961,0.959,0.957,0.955,0.953,0.951,0.949,0.947,0.945,0.943,0.941,0.939,0.938,0.936,0.934,0.932,0.93,0.928,0.926,0.924,0.923,0.921,0.919,0.917,0.915,0.914,0.912,0.91,0.908,0.906,0.905,0.903,0.901,0.899,0.898,0.896,0.894,0.893,0.891,0.889,0.887,0.886,0.884,0.882,0.881,0.879,0.877,0.876,0.874,0.872,0.871,0.869,0.686,0.866,0.864,0.863,0.861,0.86,0.858,0.856,0.855,0.853,0.852,0.85,0.849,0.847,0.845,0.844,0.842,0.841,0.839,0.838,0.836,0.835,0.833,0.832,0.83,0.829,0.827,0.826,0.825,0.823,0.822,0.82,0.819,0.817,0.816,0.814,0.813,0.812,0.81,0.809,0.807,0.806,0.805,0.803,0.802,0.8,0.799,0.798,0.796,0.795,0.794,0.792,0.791,0.79,0.788,0.787,0.786,0.784,0.783,0.782,0.78,0.779,0.778,0.776,0.775,0.774,0.772,0.771,0.77,0.769,0.767,0.766,0.765,0.764,0.762,0.761,0.76,0.759,0.757,0.756,0.755,0.754,0.752,0.751,0.75,0.749,0.748,0.746,0.745,0.744,0.743,0.742,0.74,0.739,0.738,0.737,0.736,0.735,0.733,0.732,0.731,0.73,0.729,0.728,0.727,0.725,0.724,0.723,0.722,0.721,0.72,0.719,0.718,0.717,0.715,0.714,0.713,0.712,0.711,0.71,0.709,0.708,0.707,0.706,0.705,0.704,0.702,0.701,0.7,0.699,0.698,0.697,0.696,0.695,0.694,0.693,0.692,0.691,0.69,0.689,0.688,0.687,0.686,0.685,0.684,0.683,0.682,0.681,0.68,0.679,0.678,0.677,0.676,0.675,0.674,0.673,0.672,0.671,0.67,0.699,0.668,0.667,0.666,0.665,0.664,0.663,0.662,0.662,0.661,0.66))
Final_table<-Final_table %>% mutate(reactive(Pbt=input$Pc*(1-input$R)+Pt*input$R),
reactive(TEMP=input$Twh+GTemp*depth),
Temp=ceiling(TEMP))
Final_table<-merge(x=Final_table,y=CT_data,by = "Temp",all.x = T)
Final_table<-Final_table%>%select(depth,Pc,Pt,Pbt,TEMP,Ct)
Final_table<-Final_table %>% mutate(Pb=Pbt*Ct,
Pvo=reactive(Pb/(1-input$R)))
output$table<-tableOutput(Final_table)})
I tried making any variable with reactive assignment included in () but it gives this error4
"Warning: Error in : Operation not allowed without an active reactive context.
You tried to do something that can only be done from inside a reactive consumer.
58:
Error : Operation not allowed without an active reactive context.
You tried to do something that can only be done from inside a reactive consumer."
I am pretty sure i did it to only the reactive assigned variables when recalling them
EDIT
After I tried to solve the problem it gives:
Warning: Error in data.frame: arguments imply differing number of rows: 1, 0
1: runApp
whenever I press the action button
the new server
library(shiny)
library(ggplot2)
library(dplyr)
shinyServer(function(input, output) {
plot<-reactiveVal(NULL)
Final_table<-reactiveVal(data.frame())
observeEvent(input$submit,{
plot(ggplot()+
coord_cartesian(xlim = c(0,input$Pwf+500))+
scale_y_continuous(trans = "reverse")+
scale_x_continuous(position = "top"))
#Flowing Gradient
#slope Gf
#point (pwf,Dmax)
#get p1 at depth 4000ft
p1=input$Pwf-input$Gf*(input$Dmax-4000)
flowing_gradient<-data.frame(D=c(4000,input$Dmax),P=c(p1,input$Pwf))
plot(plot()+
geom_point(data = flowing_gradient,aes(x=P,y=D))+
geom_line(data = flowing_gradient,aes(x=P,y=D)))
#casing gradient
casing_gradient<-data.frame(D=c(0,input$D1),P=c(input$Pso,input$Pcs))
plot(plot()+geom_point(data=casing_gradient,aes(x=P,y=D))+
geom_line(data=casing_gradient,aes(x=P,y=D)))
Gc=(input$Pso-input$Pcs)/(0-input$D1)
#killing gradient
killing_gradient<-data.frame(D=c(0,input$D2),P=c(input$Pko,input$Pk))
plot(plot()+geom_point(data=killing_gradient,aes(x=P,y=D))+
geom_line(data=killing_gradient,aes(x=P,y=D)))
Gk=(input$Pko-input$Pk)/(0-input$D2)
#balance point
d1=(input$Pwf-input$Pso-input$Gf*input$Dmax)/(Gc-input$Gf)
d_balance_point=d1
#operating_point
d1=(input$Pso-input$Pwf+input$Gf*input$Dmax-input$P_across_valve)/(input$Gf-Gc)
D_operating_point=d1
P_operating_point_casing=input$Pso+D_operating_point*Gc
P_operating_point_formation=input$Pwf-input$Gf*(input$Dmax-D_operating_point)
plot(plot()+geom_point(aes(x=P_operating_point_formation,y=D_operating_point)))
#Tubing grad
tubing_grad<-data.frame(D=c(0,D_operating_point),P=c(input$Pwh,P_operating_point_formation))
plot(plot()+geom_point(data = tubing_grad,aes(x=P,y=D))+
geom_line(data = tubing_grad,aes(x=P,y=D)))
#Tubing_design_grad
Pwh_design=input$Pwh+0.2*(input$Pso-input$Pwh)
Gtd=(Pwh_design-P_operating_point_formation)/(0-D_operating_point) #Tubing design grad
tubing_design_grad<-data.frame(D=c(0,D_operating_point),P=c(Pwh_design,P_operating_point_formation))
plot(plot()+geom_point(data = tubing_design_grad,aes(x=P,y=D))+
geom_line(data = tubing_design_grad,aes(x=P,y=D)))
#first valve
D_valve1=(input$Pwh-input$Pko)/(Gk-input$GL)
PK_valve1=D_valve1*Gk+input$Pko
PTD_valve1=Gtd*D_valve1+Pwh_design
df<-data.frame(D=c(0,D_valve1),P=c(input$Pwh,PK_valve1))
#ploting
plot(plot()+geom_point(data = df, aes(x=P,y=D))+
geom_line(data = df, aes(x=P,y=D)))
df<-data.frame(D=c(D_valve1,D_valve1),P=c(PTD_valve1,PK_valve1))
plot(plot()+geom_point(data = df, aes(x=P,y=D))+
geom_line(data = df, aes(x=P,y=D)))
Final_table(data.frame(depth=D_valve1,
Pc=PK_valve1,
Pt=PTD_valve1))
dvalve=D_valve1
PTDvalve=PTD_valve1
Pcvalve=PK_valve1
D_valve=D_valve1
PTD_valve=PTD_valve1
while (dvalve<D_operating_point) {
dvalve=(PTDvalve-input$Pso-dvalve*input$GL)/(Gc-input$GL)
Pcvalve=input$Pso+Gc*dvalve
if(dvalve<D_operating_point){
df<-data.frame(D=c(D_valve,dvalve),P=c(PTD_valve,Pcvalve))
plot(plot()+geom_point(data = df, aes(x=P,y=D))+
geom_line(data = df, aes(x=P,y=D)))
PTDvalve=Gtd*dvalve+Pwh_design
df<-data.frame(D=c(dvalve,dvalve),P=c(PTDvalve,Pcvalve))
plot(plot()+geom_point(data = df, aes(x=P,y=D))+
geom_line(data = df, aes(x=P,y=D)))
valve<-c(dvalve,Pcvalve,PTDvalve)
Final_table(rbind(Final_table(),valve))
D_valve=dvalve
PTD_valve=PTDvalve
}}
valve<-c(D_operating_point,P_operating_point_casing,P_operating_point_formation)
Final_table(rbind(Final_table(),valve))
GTemp=(input$Tres-input$Twh)/input$Dmax
CT_data<-data.frame(Temp=c(61:300),Ct=c(0.998,0.996,0.994,0.991,0.989,0.987,0.985,0.983,0.981,0.979,0.977,0.975,0.973,0.971,0.969,0.967,0.965,0.963,0.961,0.959,0.957,0.955,0.953,0.951,0.949,0.947,0.945,0.943,0.941,0.939,0.938,0.936,0.934,0.932,0.93,0.928,0.926,0.924,0.923,0.921,0.919,0.917,0.915,0.914,0.912,0.91,0.908,0.906,0.905,0.903,0.901,0.899,0.898,0.896,0.894,0.893,0.891,0.889,0.887,0.886,0.884,0.882,0.881,0.879,0.877,0.876,0.874,0.872,0.871,0.869,0.686,0.866,0.864,0.863,0.861,0.86,0.858,0.856,0.855,0.853,0.852,0.85,0.849,0.847,0.845,0.844,0.842,0.841,0.839,0.838,0.836,0.835,0.833,0.832,0.83,0.829,0.827,0.826,0.825,0.823,0.822,0.82,0.819,0.817,0.816,0.814,0.813,0.812,0.81,0.809,0.807,0.806,0.805,0.803,0.802,0.8,0.799,0.798,0.796,0.795,0.794,0.792,0.791,0.79,0.788,0.787,0.786,0.784,0.783,0.782,0.78,0.779,0.778,0.776,0.775,0.774,0.772,0.771,0.77,0.769,0.767,0.766,0.765,0.764,0.762,0.761,0.76,0.759,0.757,0.756,0.755,0.754,0.752,0.751,0.75,0.749,0.748,0.746,0.745,0.744,0.743,0.742,0.74,0.739,0.738,0.737,0.736,0.735,0.733,0.732,0.731,0.73,0.729,0.728,0.727,0.725,0.724,0.723,0.722,0.721,0.72,0.719,0.718,0.717,0.715,0.714,0.713,0.712,0.711,0.71,0.709,0.708,0.707,0.706,0.705,0.704,0.702,0.701,0.7,0.699,0.698,0.697,0.696,0.695,0.694,0.693,0.692,0.691,0.69,0.689,0.688,0.687,0.686,0.685,0.684,0.683,0.682,0.681,0.68,0.679,0.678,0.677,0.676,0.675,0.674,0.673,0.672,0.671,0.67,0.699,0.668,0.667,0.666,0.665,0.664,0.663,0.662,0.662,0.661,0.66))
Final_table(Final_table() %>% mutate(Pbt=Pc*(1-input$R)+Pt*input$R,
TEMP=input$Twh+GTemp*depth,
Temp=ceiling(TEMP)))
Final_table(merge(x=Final_table(),y=CT_data,by = "Temp",all.x = T))
Final_table(Final_table()%>%select(depth,Pc,Pt,Pbt,TEMP,Ct))
Final_table(Final_table() %>% mutate(Pb=Pbt*Ct,
Pvo=Pb/(1-input$R)))
})
output$plot<-renderPlot({
isolate(plot())
})
output$table<-renderTable({
isolate(Final_table())
})
})
Here's a MRE up to the first plot to ilustrate how to deal with reactive objects. Notice the use of () when accessing a reactive value.
library(shiny)
library(tidyverse)
# Define UI for application that draws a histogram
ui <- fluidPage(
# Application title
titlePanel("OTIS Gas Lift"),
fluidRow(column(width = 6,
numericInput(inputId = "Dmax",label = "Depth to mid perforation",value = 7500),
numericInput("Pwh","Pwh",100),
numericInput("Tres","Tres",182),
numericInput("Pso","P Casing at Surface",870),
numericInput("Psc","P Casing at Depth D1",1050),
numericInput("D1","D1",7000),
numericInput("P_across_valve","P_across_valve",100),
numericInput("GL","Load Grad",0.5),
numericInput("Pwf","Pwf",1760),
numericInput("RGOR","Required GOR",400)
),
column(width = 6,
numericInput("FGOR","Formation GOR",200),
numericInput("Twh","Twh",100),
numericInput("Pko","kill pressure at Surface",920),
numericInput("Pk","Kill Pressure at D2",1100),
numericInput("D2","D2",7000),
numericInput("T_inj","T_inj",100),
numericInput("q","Desired Production Rate STB/d",600),
numericInput("R","R",0.1534),
numericInput("Gf","Flowing Grad before inj",0.4)
)),
fluidRow(actionButton('submit' ,label = "Apply Changes",width = "100%")),
splitLayout(tableOutput(outputId = "table"),plotOutput(outputId = "plot"))
)
library(shiny)
server <- function(input, output) {
#define plot object that can be accessed inside of reactive() or observe()
plot_rv <- reactiveVal(NULL)
flowing_gradient_rv <- reactiveVal(NULL)
#inside this observer we can create regular local objects (only accesible inside the observer) like when creating functions.
#notice the code wrapped in curly braces {} to be able to pass multiple lines of code into `observeEvent()` second argument.
#input$submit corresponds to the action button created in the ui.
observeEvent(input$submit, {
plot_rv(ggplot() +
coord_cartesian(xlim = c(0, input$Pwf + 500)) +
scale_y_continuous(trans = "reverse") +
scale_x_continuous(position = "top"))
#Flowing Gradient
#slope Gf
#point (pwf,Dmax)
#get p1 at depth 4000ft
#input values are now available without calling reactive since we already are "inside" the observer
p1 <- input$Pwf - input$Gf * (input$Dmax - 4000)
flowing_gradient <- data.frame(D = c(4000, input$Dmax), P = c(p1, input$Pwf))
#to use flowing_gradient outside this observer we use flowing_gradient reactiveVal
flowing_gradient_rv(flowing_gradient)
plot_rv(plot_rv() +
geom_point(data = flowing_gradient,aes(x=P,y=D))+
geom_line(data = flowing_gradient,aes(x=P,y=D))
)
})
#to show the plots
output$plot <- renderPlot({
plot_rv()
})
output$table <- renderTable(
flowing_gradient_rv()
)
}
shinyApp(ui, server)
Edit: The edited app currently working.
library(shiny)
library(tidyverse)
# Define UI for application that draws a histogram
ui <- fluidPage(
# Application title
titlePanel("OTIS Gas Lift"),
fluidRow(
column(
width = 6,
numericInput(inputId = "Dmax", label = "Depth to mid perforation", value = 7500),
numericInput("Pwh", "Pwh", 100),
numericInput("Tres", "Tres", 182),
numericInput("Pso", "P Casing at Surface", 870),
numericInput("Psc", "P Casing at Depth D1", 1050),
numericInput("D1", "D1", 7000),
numericInput("P_across_valve", "P_across_valve", 100),
numericInput("GL", "Load Grad", 0.5),
numericInput("Pwf", "Pwf", 1760),
numericInput("RGOR", "Required GOR", 400)
),
column(
width = 6,
numericInput("FGOR", "Formation GOR", 200),
numericInput("Twh", "Twh", 100),
numericInput("Pko", "kill pressure at Surface", 920),
numericInput("Pk", "Kill Pressure at D2", 1100),
numericInput("D2", "D2", 7000),
numericInput("T_inj", "T_inj", 100),
numericInput("q", "Desired Production Rate STB/d", 600),
numericInput("R", "R", 0.1534),
numericInput("Gf", "Flowing Grad before inj", 0.4)
)
),
fluidRow(actionButton("submit", label = "Apply Changes", width = "100%")),
splitLayout(tableOutput(outputId = "table"), plotOutput(outputId = "plot"))
)
library(shiny)
library(shiny)
library(ggplot2)
library(dplyr)
server <- function(input, output) {
plot <- reactiveVal(NULL)
Final_table <- reactiveVal(data.frame())
observeEvent(input$submit, {
plot(ggplot() +
coord_cartesian(xlim = c(0, input$Pwf + 500)) +
scale_y_continuous(trans = "reverse") +
scale_x_continuous(position = "top"))
# Flowing Gradient
# slope Gf
# point (pwf,Dmax)
# get p1 at depth 4000ft
p1 <- input$Pwf - input$Gf * (input$Dmax - 4000)
flowing_gradient <- data.frame(D = c(4000, input$Dmax), P = c(p1, input$Pwf))
plot(plot() +
geom_point(data = flowing_gradient, aes(x = P, y = D)) +
geom_line(data = flowing_gradient, aes(x = P, y = D)))
# casing gradient
casing_gradient <- data.frame(D = c(0, input$D1), P = c(input$Pso, input$Pcs))
plot(plot() + geom_point(data = casing_gradient, aes(x = P, y = D)) +
geom_line(data = casing_gradient, aes(x = P, y = D)))
Gc <- (input$Pso - input$Psc) / (0 - input$D1)
# killing gradient
killing_gradient <- data.frame(D = c(0, input$D2), P = c(input$Pko, input$Pk))
plot(plot() + geom_point(data = killing_gradient, aes(x = P, y = D)) +
geom_line(data = killing_gradient, aes(x = P, y = D)))
Gk <- (input$Pko - input$Pk) / (0 - input$D2)
# balance point
d1 <- (input$Pwf - input$Pso - input$Gf * input$Dmax) / (Gc - input$Gf)
d_balance_point <- d1
# operating_point
d1 <- (input$Pso - input$Pwf + input$Gf * input$Dmax - input$P_across_valve) / (input$Gf - Gc)
D_operating_point <- d1
P_operating_point_casing <- input$Pso + D_operating_point * Gc
P_operating_point_formation <- input$Pwf - input$Gf * (input$Dmax - D_operating_point)
plot(plot() + geom_point(aes(x = P_operating_point_formation, y = D_operating_point)))
# Tubing grad
tubing_grad <- data.frame(D = c(0, D_operating_point), P = c(input$Pwh, P_operating_point_formation))
plot(plot() + geom_point(data = tubing_grad, aes(x = P, y = D)) +
geom_line(data = tubing_grad, aes(x = P, y = D)))
# Tubing_design_grad
Pwh_design <- input$Pwh + 0.2 * (input$Pso - input$Pwh)
Gtd <- (Pwh_design - P_operating_point_formation) / (0 - D_operating_point)# Tubing design grad
tubing_design_grad <- data.frame(D = c(0, D_operating_point), P = c(Pwh_design, P_operating_point_formation))
plot(plot() + geom_point(data = tubing_design_grad, aes(x = P, y = D)) +
geom_line(data = tubing_design_grad, aes(x = P, y = D)))
# first valve
D_valve1 <- (input$Pwh - input$Pko) / (Gk - input$GL)
PK_valve1 <- D_valve1 * Gk + input$Pko
PTD_valve1 <- Gtd * D_valve1 + Pwh_design
df <- data.frame(D = c(0, D_valve1), P = c(input$Pwh, PK_valve1))
# ploting
plot(plot() + geom_point(data = df, aes(x = P, y = D)) +
geom_line(data = df, aes(x = P, y = D)))
df <- data.frame(D = c(D_valve1, D_valve1), P = c(PTD_valve1, PK_valve1))
plot(plot() + geom_point(data = df, aes(x = P, y = D)) +
geom_line(data = df, aes(x = P, y = D)))
Final_table(data.frame(
depth = D_valve1,
Pc = PK_valve1,
Pt = PTD_valve1
))
dvalve <- D_valve1
PTDvalve <- PTD_valve1
Pcvalve <- PK_valve1
D_valve <- D_valve1
PTD_valve <- PTD_valve1
while (dvalve < D_operating_point) {
dvalve <- (PTDvalve - input$Pso - dvalve * input$GL) / (Gc - input$GL)
Pcvalve <- input$Pso + Gc * dvalve
if (dvalve < D_operating_point) {
df <- data.frame(D = c(D_valve, dvalve), P = c(PTD_valve, Pcvalve))
plot(plot() + geom_point(data = df, aes(x = P, y = D)) +
geom_line(data = df, aes(x = P, y = D)))
PTDvalve <- Gtd * dvalve + Pwh_design
df <- data.frame(D = c(dvalve, dvalve), P = c(PTDvalve, Pcvalve))
plot(plot() + geom_point(data = df, aes(x = P, y = D)) +
geom_line(data = df, aes(x = P, y = D)))
valve <- c(dvalve, Pcvalve, PTDvalve)
Final_table(rbind(Final_table(), valve))
D_valve <- dvalve
PTD_valve <- PTDvalve
}
}
valve <- c(D_operating_point, P_operating_point_casing, P_operating_point_formation)
Final_table(rbind(Final_table(), valve))
GTemp <- (input$Tres - input$Twh) / input$Dmax
CT_data <- data.frame(Temp = c(61:300), Ct = c(0.998, 0.996, 0.994, 0.991, 0.989, 0.987, 0.985, 0.983, 0.981, 0.979, 0.977, 0.975, 0.973, 0.971, 0.969, 0.967, 0.965, 0.963, 0.961, 0.959, 0.957, 0.955, 0.953, 0.951, 0.949, 0.947, 0.945, 0.943, 0.941, 0.939, 0.938, 0.936, 0.934, 0.932, 0.93, 0.928, 0.926, 0.924, 0.923, 0.921, 0.919, 0.917, 0.915, 0.914, 0.912, 0.91, 0.908, 0.906, 0.905, 0.903, 0.901, 0.899, 0.898, 0.896, 0.894, 0.893, 0.891, 0.889, 0.887, 0.886, 0.884, 0.882, 0.881, 0.879, 0.877, 0.876, 0.874, 0.872, 0.871, 0.869, 0.686, 0.866, 0.864, 0.863, 0.861, 0.86, 0.858, 0.856, 0.855, 0.853, 0.852, 0.85, 0.849, 0.847, 0.845, 0.844, 0.842, 0.841, 0.839, 0.838, 0.836, 0.835, 0.833, 0.832, 0.83, 0.829, 0.827, 0.826, 0.825, 0.823, 0.822, 0.82, 0.819, 0.817, 0.816, 0.814, 0.813, 0.812, 0.81, 0.809, 0.807, 0.806, 0.805, 0.803, 0.802, 0.8, 0.799, 0.798, 0.796, 0.795, 0.794, 0.792, 0.791, 0.79, 0.788, 0.787, 0.786, 0.784, 0.783, 0.782, 0.78, 0.779, 0.778, 0.776, 0.775, 0.774, 0.772, 0.771, 0.77, 0.769, 0.767, 0.766, 0.765, 0.764, 0.762, 0.761, 0.76, 0.759, 0.757, 0.756, 0.755, 0.754, 0.752, 0.751, 0.75, 0.749, 0.748, 0.746, 0.745, 0.744, 0.743, 0.742, 0.74, 0.739, 0.738, 0.737, 0.736, 0.735, 0.733, 0.732, 0.731, 0.73, 0.729, 0.728, 0.727, 0.725, 0.724, 0.723, 0.722, 0.721, 0.72, 0.719, 0.718, 0.717, 0.715, 0.714, 0.713, 0.712, 0.711, 0.71, 0.709, 0.708, 0.707, 0.706, 0.705, 0.704, 0.702, 0.701, 0.7, 0.699, 0.698, 0.697, 0.696, 0.695, 0.694, 0.693, 0.692, 0.691, 0.69, 0.689, 0.688, 0.687, 0.686, 0.685, 0.684, 0.683, 0.682, 0.681, 0.68, 0.679, 0.678, 0.677, 0.676, 0.675, 0.674, 0.673, 0.672, 0.671, 0.67, 0.699, 0.668, 0.667, 0.666, 0.665, 0.664, 0.663, 0.662, 0.662, 0.661, 0.66))
Final_table(Final_table() %>% mutate(
Pbt = Pc * (1 - input$R) + Pt * input$R,
TEMP = input$Twh + GTemp * depth,
Temp = ceiling(TEMP)
))
Final_table(merge(x = Final_table(), y = CT_data, by = "Temp", all.x = T))
Final_table(Final_table() %>% select(depth, Pc, Pt, Pbt, TEMP, Ct))
Final_table(Final_table() %>% mutate(
Pb = Pbt * Ct,
Pvo = Pb / (1 - input$R)
))
})
output$plot <- renderPlot({
plot()
})
output$table <- renderTable({
Final_table()
})
}
shinyApp(ui, server)
I want to add labels to the x and y axis where geom_segment lines end at. Something like this:
The code I'm working with:
ggplot(exp, aes(voltage)) +
geom_line(aes(y = current , colour = "current")) +
geom_segment(x = 0,
xend = 4.44993305,
y = 0.039496649, yend = max(
0.039496649)) +
geom_segment(x = 4.44993305,
xend = 4.44993305,
y = 0, yend = max(
0.039496649))+
geom_text(x = 4.44993305 + 0.1,
y = 0.039496649+0.0020, label = "MPP", check_overlap = TRUE) +
scale_colour_manual(values = c("red", "forestgreen")) +
annotate(geom = "point", x = 4.44993305, y = 0.039496649, colour = "orange", size = 3) +
labs(colour = "", x = "Voltage(V)", y = "Current(mA)", title = "P-V Curve") +
scale_y_continuous(expand = c(-0.05, 0), limits = c(0, 0.05)) +
scale_x_continuous(expand = c(0, 0), limits = c(0, 6))
reproducible code:
structure(list(current = c(0.04465198144317, 0.04463520273566,
0.04460114613175, 0.04457135125995, 0.0445214137435, 0.04453720897436,
0.04449214786291, 0.04451920464635, 0.04460586234927, 0.04455019906163,
0.04449771717191, 0.04447644948959, 0.04445287585258, 0.04446478188038,
0.04446309804916, 0.04443653672934, 0.04444691166282, 0.0444468036294,
0.04446209222078, 0.04440823569894, 0.04440270736814, 0.04439539834857,
0.04439954087138, 0.04436922073364, 0.04438590630889, 0.0443644374609,
0.04435379058123, 0.04435301944613, 0.04435969889164, 0.04429738968611,
0.04429103061557, 0.04427329823375, 0.04427855834365, 0.04435616359115,
0.04431574419141, 0.04425121843815, 0.04425748437643, 0.04426665976644,
0.04420702531934, 0.04421706870198, 0.04422586038709, 0.04420934617519,
0.04419368878007, 0.04420448094606, 0.04418215155602, 0.0441633015871,
0.04416632652283, 0.04419567808509, 0.0441645719111, 0.04414548352361,
0.0441205650568, 0.04409914091229, 0.04407843202353, 0.04408247023821,
0.0440976023674, 0.04407130554318, 0.04406511038542, 0.04406157508492,
0.04411358013749, 0.04408717527986, 0.04403834789991, 0.04397377744317,
0.04399513080716, 0.04394119232893, 0.04393403977156, 0.04395672306418,
0.04391529783607, 0.04388456046581, 0.04384018108249, 0.04377613589168,
0.04371620714664, 0.04360201209784, 0.04351374134421, 0.04337716847658,
0.04323555156589, 0.0430811829865, 0.04289939254522, 0.04273791983724,
0.04255214333534, 0.04230800643563, 0.04205309599638, 0.04180316627026,
0.04153088480234, 0.04128103330731, 0.04098862782121, 0.0406355522573,
0.04026722535491, 0.03988171741366, 0.03949664905667, 0.03904519975185,
0.03858072310686, 0.03809594735503, 0.03754813969135, 0.03698132932186,
0.03636532649398, 0.03573113679886, 0.03502003848553, 0.03427068144083,
0.03349439799786, 0.03265217319131, 0.03173480927944, 0.03077974915504,
0.0297338180244, 0.02861846797168, 0.02742668054998, 0.02613251283765,
0.02471670508385, 0.02320869639516, 0.02159749343991, 0.01984822377563,
0.01790586858988, 0.01580262370408, 0.01354998257011, 0.0110809514299,
0.008333564735949, 0.005422144662589, 0.002235329709947), voltage = c(0.0497902818024,
0.1001076325774, 0.1500261873007, 0.200014218688, 0.2499825656414,
0.2999092638493, 0.3499111533165, 0.3998158872128, 0.4498016238213,
0.5000447034836, 0.5500398874283, 0.6000450849533, 0.6499763131142,
0.6999563574791, 0.749892115593, 0.7998710870743, 0.8501480221748,
0.9000863432884, 0.9500870704651, 1.000000834465, 1.0499948263168,
1.0999064445496, 1.1499096155167, 1.1998677253723, 1.2501357793808,
1.3001333475113, 1.3500553369522, 1.4000434875488, 1.4499852657318,
1.4999231100082, 1.549925327301, 1.6001867055893, 1.6501588821411,
1.7000889778137, 1.7500828504562, 1.800025343895, 1.8499475717545,
1.899978518486, 1.949893116951, 2.0002207756042, 2.0501630306244,
2.1001031398773, 2.1501016616821, 2.2000172138214, 2.2499938011169,
2.299911737442, 2.3502452373505, 2.4001979827881, 2.4501132965088,
2.5001027584076, 2.5500218868256, 2.5999536514282, 2.6498956680298,
2.6998517513275, 2.7501895427704, 2.8001124858856, 2.8500940799713,
2.9000113010406, 2.9500093460083, 2.9999513626099, 3.0498661994934,
3.1002125740051, 3.1501111984253, 3.2001020908356, 3.2500350475311,
3.3000183105469, 3.3500154018402, 3.399943113327, 3.4499311447144,
3.5001940727234, 3.550187587738, 3.6001205444336, 3.6500551700592,
3.7000305652618, 3.7499585151672, 3.7999482154846, 3.8501899242401,
3.9001405239105, 3.9500863552094, 4.0000004768372, 4.0499835014343,
4.0999245643616, 4.1499009132385, 4.1998748779297, 4.2501282691956,
4.300087928772, 4.3500247001648, 4.3999924659729, 4.449933052063,
4.4998655319214, 4.5498738288879, 4.6001214981079, 4.6501264572144,
4.7000713348389, 4.7500491142273, 4.8000221252441, 4.8499178886414,
4.8999338150024, 4.9498329162598, 5.0001378059387, 5.0500822067261,
5.1000084877014, 5.1500005722046, 5.1999025344849, 5.2499060630798,
5.2998147010803, 5.3501005172729, 5.4000744819641, 5.4499711990356,
5.4999628067017, 5.5498695373535, 5.5998673439026, 5.6497716903687,
5.6997165679932, 5.7502884864807, 5.8000655174255, 5.8499555587769
), PP = c(0.00222323473909097, 0.00446832447547921, 0.00669133990338782,
0.0089149039981273, 0.0111295772335824, 0.0133571215574027, 0.0155682987722391,
0.0177994853036886, 0.020063789316651, 0.0222770910799081, 0.0244755193440537,
0.0266878749124022, 0.0288933163539832, 0.0311234067610935, 0.0333425266619036,
0.0355435009395142, 0.0377864540419245, 0.0400059609496442, 0.04224285894479,
0.0444082727560584, 0.0466226130110058, 0.0488307847519388, 0.0510554589725266,
0.0532371959582141, 0.0554884095769874, 0.0576796845864956, 0.0598800716882498,
0.0620961560286796, 0.0643209097851773, 0.0664426785032353, 0.068647790123336,
0.070845543246237, 0.073066656339177, 0.0754094248194155, 0.0775562239145906,
0.0796533146869037, 0.0818740257541394, 0.0841057026413645, 0.0861989743910597,
0.0884438994540186, 0.090670223963168, 0.092844186714439, 0.0950209236818901,
0.0972506190093721, 0.0994095671210524, 0.101571695684362, 0.103801698561548,
0.106078377387785, 0.108208204874005, 0.110368245128615, 0.112508406553953,
0.114655722439755, 0.116803246072698, 0.119016134475474, 0.121276764892071,
0.123404612920738, 0.125589710242767, 0.127779065687917, 0.130135473691482,
0.132259381554438, 0.134311068741467, 0.136328057755817, 0.138589554231821,
0.140616301445618, 0.142787169037195, 0.145057990983433, 0.147116924127234,
0.149205009137113, 0.151245606106401, 0.153224971374792, 0.155200735994985,
0.156972499532076, 0.158827556562052, 0.160496849197857, 0.16213152475246,
0.163706264410516, 0.165170808933627, 0.166683893064858, 0.168084640773841,
0.169232045916551, 0.170314344969572, 0.171389828259531, 0.172349056768834,
0.17337517472235, 0.174206925818462, 0.1747364477406, 0.175163424900961,
0.175479256150164, 0.175757444083009, 0.175698148550336, 0.175537422363473,
0.17524598641866, 0.174603597797929, 0.173814885869911, 0.172737086901316,
0.171510247194652, 0.169844311111882, 0.167924070855098, 0.165791673720114,
0.163265365619927, 0.160263395675946, 0.156976981940024, 0.153129179839487,
0.148813244139014, 0.143987496509493, 0.138497475713147, 0.132236856654388,
0.125328689163156, 0.11770571721887, 0.109164492545057, 0.0993752346268299,
0.0884925964284587, 0.0765543079295968, 0.063158282454129, 0.0479204013524691,
0.0314487942879752, 0.0130765794624036)), row.names = c(NA, -117L
), class = c("tbl_df", "tbl", "data.frame"))
I made a package specifically for this. lemon
library(lemon)
ggplot(exp, aes(voltage)) +
... +
annotate_x_axis('IM', x = 4.44993305, side = 'bottom', print_value = FALSE) +
annotate_y_axis('M', y = 0.039496649, side='left', print_value = FALSE)
(where the ... is placeholder for the rest of your ggplot-commands)
I would like a fairly plain, publication-quality cluster plot. I have created the plot and removed the title, legend and adjusted the axis titles, with the script provided. However, I would also like to remove all of the individual row labels 'attributes' that are my sample ID's within each of the two cluster's e.g. CLR45, HTR132. Is this possible?
fviz_cluster(k2, data = Chem)+ theme(legend.position = "none")+labs(title = "") + theme(
axis.title.x = element_text(margin = unit(c(3, 0, 0, 0), "mm")),
axis.title.y = element_text(margin = unit(c(0, 3, 0, 0), "mm")))
dput(head(Chem,50))
structure(c(0.147411356827536, -0.94833184269442, -0.236098761737746,
-0.156408346996621, -1.07782876612066, 0.15737266025443, -0.85369947703763,
-0.684357344128487, -0.744125156240499, -0.166369650423515, 1.06883177595158,
-1.72531338325188, -1.16249983257523, -0.908486633211519, -1.30693870691714,
-1.04296420835121, 0.336676092365792, -0.45026675161856, -0.455247403332007,
-0.935222767283235, -0.798912316639064, 0.185622913832727, -0.345812539076084,
0.264855107585394, -0.649213869051943, -0.745838498773852, -0.952615203252478,
0.510998876988382, 1.40751604176986, -0.749105803729271, 0.222121124079889,
0.146973059409158, -0.25104071265341, -0.176330949625734, -0.734163852813605,
1.1584834941196, 0.869605741211104, 0.202198517226101, 0.301811538821014,
-0.0567953296263845, -0.669415393212821, -0.191272904766074,
-0.71922190189794, 0.222121124079889, -0.51999586293279, -0.231118110024299,
0.5608053856735, -0.285905270422864, -0.614628232814256, 0.0378370402550813,
1.21148988263212, -0.722729092058211, 0.938866964062205, 1.29275958711264,
1.23956487191698, 1.86977449177269, 1.84761002727152, 2.09068032585176,
0.430561900436177, -0.339283848035902, 3.19668712695198, -0.305298335931744,
-0.0186379222283033, 3.76926913851535, -0.987963856121806, 0.356680351444172,
3.44123505721924, 0.255462628028634, -1.00052371956831, -0.425184448439876,
-0.0334142322231424, -0.313100227585446, -1.0460909046001, 0.779075947446034,
-1.04523092273039, -0.432924280356334, -0.788096532267007, 0.836910424803157,
0.471935569011041, -0.841678386878241, 3.4264587472244, 0.770476135624245,
1.97394747659788, 0.635952609659098, -0.86162640581326, -0.502562073822641,
0.695796664499772, -0.659190958982183, 0.126169915328244, -0.127243800150166,
-0.945851372685624, -0.589742302104659, -0.506994966919312, -0.665840298627189,
-0.90004481199628, -0.82320799963024, -0.566839021759986, -0.759669866554213,
-0.980575700633291, 0.208917251495781, -1.23882313589815, -0.816688277463794,
0.346387764578252, 0.524062438145321, 1.46662027130976, -0.917496601945682,
1.0860688452788, 2.10423292402831, 0.254400170526879, -0.804087236829436,
-0.843150462529107, -0.300045614716482, 0.672754716385498, -0.9527795153661,
-0.622632253058524, 0.0175006072532231, 0.578246912369032, 1.71864108103204,
-1.24512365636358, 2.67546329317061, -1.0435070073998, -1.24421134102627,
1.42382713735224, 2.28432699595981, 0.587773297320356, 0.00106885031820219,
0.211304610661984, -0.589869547527789, 0.65259305148912, 0.00867987889811877,
-1.54754862951275, 0.235750629237659, -0.331548216154132, 1.18561706626058,
-0.368091233667634, -1.09769148192, -1.03846659132395, -0.70957943281297,
-0.316426967333605, -1.05358783984799, -1.19471949412263, -0.788965988305396,
0.663933988919855, 0.346387764578252, 0.137210492538405, 0.146031220893509,
-0.456298517515165, -0.534424969210994, 0.450976402525343, 0.193915175837746,
1.53543257619906, -0.518118831649496, -0.16974850422888, 0.380309904408398,
-0.518118831649496, -0.114742659464473, 3.20394309995186, 1.0953858473389,
0.893697766122234, 0.710344953491444, -0.316430750432833, 0.453651027510375,
-0.444777708547519, 1.99381459314849, -0.664801077853449, 1.99381459314849,
0.343639347733259, 0.105280700089759, -0.811483324057402, 3.43885470777859,
-0.829818602394972, 0.948923628687728, -1.17727227024187, 0.507850124084635,
-0.054162900383238, 0.0383202589981529, -0.111075611598317, 0.215292379866875,
-0.243089627330857, -0.609795233089042, -0.499783553311926, -0.367182807190326,
-0.719806922617856, 0.105280700089759, -0.353101307107973, 0.728680241580711,
-0.848153880732542, -0.994836126936495, -1.26986533125513, -0.976500848598925,
0.398645192497665, -1.01317140527406, 0.123615978427329, -0.774812757630565,
-1.08651252837604, -0.646465799515879, -0.536454109987066, -0.829818602394972,
0.508656872274782, -0.518118831649496, 0.675002376238412, -0.0617082448613822,
-0.668996727923662, -1.60481832778947, -0.71877447345135, 0.625224632383091,
-1.78899598306442, -0.793441090906698, -1.09210755738336, 1.32211305639179,
-1.96321808990278, -1.51521838684306, 0.00549171084843096, -2.9911285157337,
0.276780418706376, -2.1225068715777, -1.56499613237074, -0.683930051414732,
0.271802645324263, 0.398636337390084, -0.270774772063992, 0.662607717406351,
1.26287754043467, -0.00695272427921605, 0.459290519580567, -0.0828886740640689,
-0.779976209944577, 0.525669143000081, 1.64566839646848, -0.527130156430866,
-1.99806251026703, 0.852509813910332, -1.05477425032805, 0.0726916665582448,
0.177224929323366, 0.824335611149109, -0.444996877229983, -0.0218860477702858,
-1.2713074392762, -0.270774772063992, -0.0467749213703124, 0.625224632383091,
-0.569441240213019, 0.722291233402677, 0.401224781689411, 0.127447185468045,
0.80442451260356, -0.594330112140679, 0.824335611149109, 0.276780418706376
), .Dim = c(50L, 5L), .Dimnames = list(c("CLR16", "CLR36", "CLR52",
"CLR56", "CLR20", "CLR22", "CLR11", "CLR14", "CLR17", "CLR33",
"CLR41", "CLR43", "CLR50", "CLR32", "CLR35", "CLR37", "CLR45",
"CLR48", "CLR49", "CLR5", "CLR55", "CLR58", "CLR59", "CLR6",
"CLR60", "CLR61", "CLR62", "CLR65", "CLR66", "CLR67", "CLR68",
"CLR7", "GGR70", "GGR77", "GGR71", "GGR69", "GGR72", "GGR73",
"GGR74", "GGR75", "GGR76", "GGR78", "GGR79", "GGR80", "GGR81",
"GGR83", "GGR84", "GGR85", "GGR87", "GGR89"), c("X88Sr_umol_molCa",
"X138Ba_umol_molCa", "X25Mg_umol_molCa", "X55Mn_umol_molCa",
"X7Li_umol_molCa")))
You can use labelsize = 0 as shown in the following code
library("factoextra")
# Data preparation
data("iris")
head(iris)
# Remove species column (5) and scale the data
iris.scaled <- scale(iris[, -5])
# K-means clustering
km.res <- kmeans(iris.scaled, 3, nstart = 25)
# Visualize kmeans clustering
fviz_cluster(km.res, iris[, -5], labelsize = 0) +
theme(legend.position = "none") + labs(title = "") +
theme(axis.title.x = element_text(margin = unit(c(3, 0, 0, 0), "mm")),
axis.title.y = element_text(margin = unit(c(0, 3, 0, 0), "mm")))
To remove all the little geometric shapes use geom = NULL like
fviz_cluster(km.res, iris[, -5], geom = NULL, labelsize = 0) +
theme(legend.position = "none") + labs(title = "") +
theme(axis.title.x = element_text(margin = unit(c(3, 0, 0, 0), "mm")),
axis.title.y = element_text(margin = unit(c(0, 3, 0, 0), "mm")))
To remove cluster centers use show.clust.cent = F
fviz_cluster(km.res, iris[, -5], geom = NULL, labelsize = 0, show.clust.cent = F) +
theme(legend.position = "none") + labs(title = "") +
theme(axis.title.x = element_text(margin = unit(c(3, 0, 0, 0), "mm")),
axis.title.y = element_text(margin = unit(c(0, 3, 0, 0), "mm")))
How
1) to increase the size of the text inside the yellow circle of PCA-Bioplot using ggplot2?
2) what we called it?
USED Code:
p <- fviz_pca_biplot(zom, col.ind = df$Rm,
palette = "jco",
geom.ind = "point",
gradient.cols = c("white", "#2E9FDF", "#FC4E07" ),
pointsize = 3,
legend.title = "",
title = "PCA - Biplot")
p + theme(
panel.background = element_rect(fill = "lightblue",
colour = "lightblue",
size = 0.5, linetype = "solid"),
panel.grid.major = element_line(size = 0.5, linetype = 'solid',
colour = "white"),
panel.grid.minor = element_line(size = 0.25, linetype = 'solid',
colour = "white")
) +
theme(axis.text.x = element_text(size = 15)) +
theme(axis.text.y = element_text(size = 15)) +
theme(axis.title = element_text(size = 15, face = "bold"))
here is the output of dput(zom)
structure(list(sdev = c(1.3869502921823, 1.05877006549918,
1.0384037123946,
1.02795716229601, 0.816102138623649, 0.392904488803137), rotation = structure(c(-0.680441687434053,
0.590163481953139, -0.249790660774574, 0.256430440458904, -0.221341290032775,
-0.107527963308749, 0.0294273368056, -0.00209518665138356, -0.00651856640667369,
0.725574197057669, 0.662242320319373, 0.184565284047572, 0.0458337707228322,
0.466044566553159, 0.868088194460935, -0.060792787460819, 0.105497140660582,
-0.110901778120757, -0.0216966746984257, -0.021753686428234,
-0.16212211830016, -0.165694951555159, 0.424605461060344, -0.874658696668905,
0.213195863024978, -0.235202123804291, 0.172581273328464, 0.612922824182556,
-0.562795160546884, -0.42074981628564, 0.698648112863565, 0.615395705894065,
-0.357655062278663, 0.0309926666830973, -0.0654622449952845,
-0.00399312882564253), .Dim = c(6L, 6L), .Dimnames = list(c("Rm",
"IC", "Dose", "CT", "pH", "Na"), c("PC1", "PC2", "PC3", "PC4",
"PC5", "PC6"))), center = c(Rm = 83.7809291198966, IC = 253.125,
Dose = 9.4375, CT = 107.5, pH = 4.5625, Na = 0.0190625), scale = c(Rm = 28.5351607580893,
IC = 477.02821829807, Dose = 2.53735253655002, CT = 31.7141841087582,
pH = 1.89632608788123, Na = 0.0885803604822079), x = structure(c(2.86546265651538,
2.86546265651538, 2.86546265651538, 0.60097528700688, 0.61271514739821,
0.641028928342007, -0.00166899411927806, 0.0135237663871491,
0.00799912620299387, -0.502873485889389, -0.500801745820331,
-0.497348845705234, -0.994409857337228, -0.995100437360248, -0.99531410281937,
0.793079692895072, 0.814699819791746, 0.758741844294473, -0.497841091145642,
-0.495933432890053, -0.496569318975249, -0.732555087675326, -0.735098632016111,
-0.734462745930915, -0.967904970290207, -0.967269084205011, -0.969812628545796,
-1.2007113085643, -1.20261896681989, -1.2007113085643, -1.42970233032722,
-1.4335176468384, -1.42715878598644, -1.42310449838764, -1.41665970698363,
-1.41988210268563, -1.34353675243178, -1.34224779415098, -1.34353675243178,
-1.21967377951517, -1.21902930037477, -1.22031825865558, -0.984837416489995,
-0.984192937349593, -0.98290397906879, -0.740978345499194, -0.742911782920398,
-0.742911782920398, -0.500986149350802, -0.5003416702104, -0.5003416702104,
-0.510547262560963, -0.51312517912257, -0.511836220841767, -0.604331031137238,
-0.606908947698845, -0.60497551027764, -1.0228663914062, -1.02093295398499,
-1.04348972389905, -0.523599248811126, -0.530861907144586, -0.527230577977856,
-0.497501592642528, -0.502890457771311, -0.500869633348017, -0.462781288821409,
-0.467708092167455, -0.468200772502059, -0.423803526770102, -0.434544845776796,
-0.435977021644356, -0.319071745898057, -0.338233491768927, -0.338039938780333,
-0.228567562788233, -0.238737064518394, -0.243821815383475, 0.25922674074255,
0.221155289964151, 0.22301243390456, 1.21671761800511, 1.21432346858796,
1.52077459398376, 2.07813858975284, 2.08093738414191, 2.07394039816924,
2.39845560227458, 2.64196689212576, 2.67412876059667, 3.21201297175126,
2.94149420651544, 2.9555211054536, 3.66033884779045, 3.70419306056261,
3.61374374672004, -0.0114380621485446, -0.0114380621485446, -0.0114380621485446,
0.0728420386799, 0.0723343201903272, 0.0711098226566515, 0.0784251894042363,
0.077768141947142, 0.0780070682951763, 0.0659682324113423, 0.0658786350308294,
0.065729306063308, 0.0530931543093882, 0.0531230201028926, 0.0531322605794027,
-0.67843033279501, -0.679365347165407, -0.676945309971438, 0.0657505944009178,
0.0656680931329416, 0.0656955935556004, 0.764253319560671, 0.764363321251306,
0.764335820828648, 1.46278354514308, 1.46275604472043, 1.46286604641106,
2.16120376903486, 2.16128627030284, 2.16120376903486, 2.85945899039069,
2.85962399292664, 2.85934898870005, -2.56547983623093, -2.56575855673085,
-2.56561919648089, -2.33663870242347, -2.33669444652346, -2.33663870242347,
-1.99357210606224, -1.99359997811223, -1.99354423401224, -1.30688147233992,
-1.30690934438992, -1.3069650884899, -0.620581047317498, -0.620497431167523,
-0.620497431167523, 0.0658866100048786, 0.0658587379548867, 0.0658587379548867,
0.0866110365655697, 0.0867225247655376, 0.0866667806655536, 0.273465340211693,
0.273576828411661, 0.273493212261685, 1.10400323743889, 1.10391962128891,
1.10489514303863, 0.065636765647606, 0.0659508567693429, 0.0657938112084745,
0.0657359119718712, 0.0659689664011826, 0.0658815709901908, 0.0654621511663813,
0.0656752226229314, 0.0656965297685864, 0.0650042663432287, 0.0654688005097615,
0.0655307383986326, 0.0629304930929429, 0.0637591888650256, 0.0637508182006611,
0.0614720265162713, 0.0619118310698211, 0.062131733346596, 0.0428317934501707,
0.0444782848768771, 0.0443979682219158, 0.013700820438679, 0.0138043611866411,
0.000551145447487342, 0.00100264361519338, 0.000881603022505242,
0.00118420450422559, -0.000572213614854114, -0.0111034448353269,
-0.0124943621663328, -0.0234784360129627, -0.01177920158356,
-0.0123858285539735, -0.0183113221897244, -0.0202079030627412,
-0.016296205012144, -3.59319854690713, -3.59319854690713, -3.59319854690713,
-2.76968040684304, -2.77047119035826, -2.77237837413028, -1.7226096733703,
-1.72363304027236, -1.72326090685343, -0.0113869364898592, -0.0115264865219577,
-0.0117590699087883, 1.69918456690746, 1.69923108358482, 1.6992454758448,
-0.194221221837599, -0.195677528759236, -0.191908263785587, -0.0117259128211618,
-0.011854410490718, -0.0118115779341992, 0.0996245198176483,
0.0997958500437233, 0.0997530174872045, 0.211017785012977, 0.210974952456458,
0.211146282682533, 0.322239719982231, 0.322368217651787, 0.322239719982231,
0.433204659612372, 0.433461654951485, 0.433033329386297, 0.208408019332093,
0.207973905583592, 0.208190962457842, 0.189325883721603, 0.189239060971902,
0.189325883721603, 0.160398800681917, 0.160355389307067, 0.160442212056767,
0.103412862099547, 0.103369450724697, 0.103282627974997, 0.0458191642692768,
0.045949398393827, 0.045949398393827, -0.0115140653118934, -0.0115574766867435,
-0.0115574766867435, -0.0242076167494765, -0.0240339712500762,
-0.0241207939997764, -0.137928643189524, -0.137754997690123,
-0.137885231814674, -0.643239663701245, -0.643369897825795, -0.641850499706042,
-0.0364985972647002, -0.0360093929389785, -0.0362539951018394,
-0.0117487810504896, -0.0113857932833816, -0.0115219136960471,
0.0124202235191262, 0.0127520873351289, 0.0127852737167291, 0.036302450591143,
0.0370259735053109, 0.0371224432272, 0.08226328682603, 0.0835540000246974,
0.0835409625176402, 0.129182477708807, 0.129867483667838, 0.130209986647354,
0.149340662283331, 0.151905111490791, 0.1517800164075, 0.349922419926923,
0.350083687082491, 0.329441491169845, 0.822052579751251, 0.821864056175024,
0.822335365115591, 1.06555363726496, 1.04915099640157, 1.04698460987244,
1.27583059071595, 1.29405242410891, 1.29310758830335, 1.77578636183525,
1.77283239242016, 1.77892495433878, 0.672936886655186, 0.672936886655186,
0.672936886655186, 0.479220758179566, 0.479595097284032, 0.480497915124216,
0.277739272329123, 0.278223711170197, 0.278047551591625, -0.0420180024733124,
-0.0419519426313478, -0.0418418428947401, -0.361466998013246,
-0.361489017960568, -0.361495830932269, -0.455957641564343, -0.455268258669557,
-0.457052543809002, -0.0418575387131908, -0.0417967108107098,
-0.0418169867782035, 0.405920946144967, 0.405839842274993, 0.405860118242486,
0.853679155035632, 0.853699431003125, 0.853618327133151, 1.30151846779627,
1.30145763989379, 1.30151846779627, 1.74947943636187, 1.74935778055691,
1.74956054023185, 0.559121494788181, 0.559326994458725, 0.559224244623453,
0.506834071572686, 0.506875171506794, 0.506834071572686, 0.428546786518823,
0.428567336485878, 0.428526236551769, 0.271561217070011, 0.271581767037066,
0.271622866971174, 0.114863347159961, 0.114801697258797, 0.114801697258797,
-0.0419578225524164, -0.041937272585362, -0.041937272585362,
-0.140617453481398, -0.140699653349615, -0.140658553415506, -1.02880073144688,
-1.0288829313151, -1.02882128141394, -4.97633676676118, -4.97627511686002,
-4.97699436570692, -0.0405525920849589, -0.0407841703938968,
-0.0406683812394278, -0.041846713408512, -0.0420185436415093,
-0.0419541073041353, -0.0428658915817397, -0.0430229884373209,
-0.043038698122879, -0.0437493157469923, -0.0440918151978991,
-0.0441374817913533, -0.0446623719840725, -0.0452733665402437,
-0.0452671948780602, -0.0460290917254437, -0.0463533581173464,
-0.0465154913132977, -0.0347277538465103, -0.0359417063395607,
-0.0358824891447778, -0.0254597979394965, -0.0255361381785541,
-0.0157645875791891, -0.0405178971936921, -0.0404286543790193,
-0.0406517614157015, -0.0515669711290927, -0.0438023303981306,
-0.0427768118110223, -0.0468885025423077, -0.0555143080411957,
-0.0550670440523645, -0.0751186194383116, -0.0737202768525403,
-0.0766043584356935, -0.668641240557885, -0.668641240557885,
-0.668641240557885, 0.115210292634065, 0.111531961758482, 0.102660693176194,
0.415544844033262, 0.410784651135449, 0.412515630371017, 0.758439070992234,
0.757789953778896, 0.756708091756666, 1.09830408428896, 1.09852045669341,
1.09858740231534, 1.01909703201597, 1.0123230178755, 1.02985576035672,
0.756862322006555, 0.756264614876513, 0.756463850586527, 0.16369709766401,
0.164494040504066, 0.164294804794052, -0.429268890968521, -0.429468126678535,
-0.42867118383848, -1.02303182244111, -1.02243411531107, -1.02303182244111,
-1.61799016817378, -1.61679475391369, -1.61878711101383, -1.46711799255508,
-1.46913727339982, -1.46812763297745, -1.27344956363829, -1.27385341980724,
-1.27344956363829, -0.984360416854425, -0.984562344938899, -0.984158488769951,
-0.402143561597215, -0.402345489681689, -0.402749345850636, 0.177246300477365,
0.177852084730785, 0.177852084730785, 0.757847731058786, 0.757645802974312,
0.757645802974312, 0.709540797223577, 0.710348509561471, 0.709944653392524,
0.277201529720376, 0.278009242058271, 0.27740345780485, -1.64376785095747,
-1.64437363521089, -1.63730615225432, 0.76756856738881, 0.769844102147852,
0.768706334768331, 0.756755950398666, 0.758444388619123, 0.757811224286452,
0.743241687048829, 0.744785352157408, 0.744939718668266, 0.728393477677695,
0.731758945752254, 0.732207674828863, 0.690307527141652, 0.696311281796089,
0.696250637809681, 0.656679364891814, 0.659865671283581, 0.661458824479464,
0.498572335960762, 0.510500875841853, 0.509918995847653, 0.172214430172341,
0.172964564622694, 0.0769473549774294, -0.15039991278267, -0.151276830520407,
-0.149084536176064, -0.277118621709646, -0.353415533781453, -0.363492484432446,
-0.558379307593243, -0.473620418354126, -0.47801532372208, -0.751562771947797,
-0.765303165741861, -0.736963603541604, -0.950551140925346, -0.950551140925346,
-0.950551140925346, 0.890455667090167, 0.878401685890669, 0.849330319468351,
0.783118353632983, 0.767519083845397, 0.773191545586337, 0.0875561076337164,
0.0854289344808635, 0.0818836458927761, -0.617932946412196, -0.617223888694578,
-0.617004506236747, -0.93434308694539, -0.956541698722385, -0.899086468240751,
0.0823890622338935, 0.0804303611947473, 0.0810832615411293, 0.0146537360723359,
0.0172653374578647, 0.0166124371114824, -0.0524286897428399,
-0.0530815900892218, -0.0504699887036933, -0.122122716943544,
-0.120164015904398, -0.122122716943544, -0.195734146222542, -0.191816744144249,
-0.19834574760807, -0.034706086263485, -0.0413233195038457, -0.0380147028836654,
-0.0236101458388703, -0.0249335924869422, -0.0236101458388703,
-0.0115982984702002, -0.0122600217942363, -0.0109365751461641,
0.0256598627478605, 0.0249981394238244, 0.0236746927757521, 0.0536538974294171,
0.0556390674015252, 0.0556390674015252, 0.0856182720551895, 0.0849565487311537,
0.0849565487311537, 0.082520587093274, 0.0851674803894179, 0.0838440337413459,
0.0625821023244647, 0.0652289956206089, 0.0632438256485009, -0.024268790006146,
-0.026253959978254, -0.00309364363699328, 0.0448281541005945,
0.0522851377521673, 0.048556645926381, 0.082040479845571, 0.0875735336284713,
0.0854986384598838, 0.110399443691105, 0.115458072407909, 0.115963935279589,
0.134387033452647, 0.145415755519914, 0.14688625179555, 0.154869509916844,
0.174543962318986, 0.17434523047654, 0.189960268781612, 0.200401873585886,
0.205622675988024, -0.182869295310527, -0.143779175273041, -0.145686010396821,
-0.52589683056877, -0.523438621433295, -0.838089390774116, -0.130201229032513,
-0.133074910134547, -0.125890707379461, 0.180993818464076, -0.0690330482863351,
-0.102055464649597, -0.0142490124624156, 0.263507962626653, 0.249105749103516,
0.805594777492901, 0.760567167397577, 0.853436613219184), .Dim = c(96L,
6L), .Dimnames = list(NULL, c("PC1", "PC2", "PC3", "PC4", "PC5",
"PC6")))), class = "prcomp")
many thanks
best regards
Suraj
You can change the size of the label by using labelsize = 6 like
p <- fviz_pca_biplot(zom,
palette = "jco",
geom.ind = "point",
gradient.cols = c("white", "#2E9FDF", "#FC4E07" ),
pointsize = 3, labelsize = 6,
legend.title = "",
title = "PCA - Biplot")
p + theme(
panel.background = element_rect(fill = "lightblue",
colour = "lightblue",
size = 0.5, linetype = "solid"),
panel.grid.major = element_line(size = 0.5, linetype = 'solid',
colour = "white"),
panel.grid.minor = element_line(size = 0.25, linetype = 'solid',
colour = "white")
) +
theme(axis.text.x = element_text(size = 15)) +
theme(axis.text.y = element_text(size = 15)) +
theme(axis.title = element_text(size = 15, face = "bold"))
Note in your dataset Rm was not there so I have removed col.ind = df$Rm part.
You can directly edit the font size of both the text layers of this object in the 'aes_params' section of the ggplot object. It seems that the two text layers are layers 2 and 5 when using this function but yours may be different so look for the one that says GeomText.
Here is some example code:
library(factoextra)
data("decathlon2")
df <- decathlon2[1:23, 1:10]
library("FactoMineR")
test <- PCA(df, graph = FALSE)
p <- fviz_pca_biplot(res.pca)
p
Then use:
p$layers[[5]]$aes_params$size <- 10
p
Hope that is what you are looking for! Again you may need to change the layer number to something other than 5 here.
I'm doing some single particle tracking experiments, and I've made a plot that looks like this
And an excerpt of the data like this
Tracks_subset <- structure(list(x = c(50.9870663039413, 51.1454673261645, 51.2438755862949,
51.2095459932038, 51.6660042216598, 50.9114140942979, 51.0024489561214,
50.8857311418507, 51.2794722111027, 51.2431331170315, 51.1686446878892,
51.6828347775235, 52.1450571292308, 52.0846161251043, 52.6398039669697,
52.8833174825244, 52.5705151101221, 47.7126603341761, 47.7043102797697,
47.7383984362003, 47.6860850023564, 47.6951829901912, 47.6699652212862,
47.7413324987855, 47.6843782373267, 47.644111020292, 47.6618622920263,
47.6541735611274, 47.6649621568611, 47.6523884564593, 47.6610279361442,
47.6512197115578, 47.6657086161767, 47.6192509459374, 47.6207586571131,
47.5774206679784, 47.6200920953012, 47.7306727739304, 47.6379509867329,
47.714775352656, 47.6550462636824, 47.6609930612728, 47.7000183950083,
47.6649651728503, 47.6539558351917, 47.6389944434634, 47.6717405874446,
47.6953802257671, 47.670156194978, 47.6659335190123, 47.6765976765644,
47.6840293686863, 47.6835120352331, 47.7206680944438, 47.6295515092937,
47.6296091556035, 47.6942899171821, 47.7250190805859, 47.5914020018512,
47.70039477981, 47.6173948003708, 47.6403690517817, 47.706224437305,
47.6278056300272, 47.7050590713087, 47.6202775363008, 47.616604053917,
47.6756516087319, 47.7266296774674, 47.6446057760854, 47.5705082443691,
47.6595393038973, 47.7454552888996, 47.6741550431176, 47.5860886147769,
47.5711827843158, 47.6032212783683, 47.6664108892973, 47.6658197925874,
48.3968244300988, 48.9904220754653, 48.8091985242839, 48.6060438195256,
47.9442329308765, 47.5918680853048, 61.7398341199382, 61.5105531711929,
61.3508575465536, 60.7780284493327, 60.9300399030291, 61.5425582885666,
61.6082571595723, 61.5298863337404, 61.7856612691648, 61.9071110539638,
62.2590343816915, 62.4185223478263, 62.9672715597194, 63.3275273995809,
63.8113387354958, 64.3231547762155, 63.7003651772996, 64.5725239608709
), y = c(25.4839360156051, 25.6047955465986, 25.4262289850266,
25.6172499551253, 25.2123769606517, 25.0385424557608, 24.966470254684,
25.0765695667183, 25.3864947576636, 25.5754234194841, 25.362590160186,
25.7772644867977, 25.5496302761478, 25.2288998273316, 25.0558763011072,
24.9078484752662, 24.976087151153, 25.3889343715977, 25.4338531136808,
25.4429033909954, 25.4318520315956, 25.3990616319309, 25.4511690945816,
25.3200107971065, 25.481502531704, 25.4813627020502, 25.4853491195569,
25.4847769218943, 25.4575428518825, 25.4557467653372, 25.4624512146039,
25.4595647154719, 25.4563293549661, 25.4804991266559, 25.3812415821813,
25.4473050286014, 25.4196869940826, 25.4442315703239, 25.479341197772,
25.4300738230213, 25.4693914326269, 25.4567345365435, 25.4674089428837,
25.4112535933299, 25.4637733103663, 25.3956145368333, 25.4990099732346,
25.4839175917237, 25.4745320245195, 25.4005315613532, 25.469591766703,
25.4539955232768, 25.4657553925353, 25.4245323404107, 25.4361711386943,
25.3891764540008, 25.466965662987, 25.1009694093232, 25.0358862503509,
25.1789725026332, 25.42714785297, 25.4795979566479, 25.468929968642,
25.4239887143419, 25.5281893742505, 25.4093001632827, 25.4384275123265,
25.4344555350342, 25.4429352491382, 25.5199514977758, 25.4910332653875,
25.4595502380103, 25.4968060944952, 25.4827240176748, 25.3698050293595,
25.4439838950347, 25.3741755234997, 25.5563892658156, 25.6960651973953,
25.7204681252841, 26.4352696253167, 27.1441226535699, 26.6615707288907,
26.3571435264103, 26.2462341038955, 25.4044026980314, 24.9429648374475,
25.316181029454, 25.5746195865509, 25.4159071371913, 25.0535276243763,
25.1404356519081, 24.9217292382466, 25.0681095303721, 25.6848864023155,
25.7992168557371, 25.2353282682059, 24.9773329424632, 24.4822347858453,
24.268105758617, 24.6415345738956, 24.0369860755695, 23.6865149091661
), steplength = c(0, 0.199243343862037, 0.203887720506984, 0.194081250972988,
0.610144455009775, 0.774354373270278, 0.116110930731278, 0.160452194371228,
0.501084477506786, 0.192391707241276, 0.225491734526058, 0.660565095527355,
0.515234739003464, 0.326375758563115, 0.581524445214716, 0.284975559445094,
0.320159087122816, 0, 0.0456882566850305, 0.035269107279719,
0.053468008239723, 0.0340291594490852, 0.0578888895422253, 0.14931773938219,
0.171240673444157, 0.0402674598162118, 0.0181933826629311, 0.00770999306101455,
0.0292931453981066, 0.0127013333423588, 0.0109357326776552, 0.0102241452834658,
0.0148457372554814, 0.0523688169390838, 0.0992689947975958, 0.079009874415496,
0.0508291898464581, 0.113271897260304, 0.0991464359452704, 0.091264765459093,
0.071508310668843, 0.0139843276580312, 0.0404588633537657, 0.066197822223741,
0.0536612168447871, 0.0697815280139674, 0.108457024734435, 0.0280466126241494,
0.0269135765181205, 0.0741208441744882, 0.06987872508325, 0.0172763670024788,
0.0117712428774199, 0.055496961741496, 0.0918569197986897, 0.0469947200495333,
0.101167000316718, 0.367284003435199, 0.148624834100549, 0.179869678487995,
0.261686837845756, 0.0572610653386249, 0.0667138499153149, 0.0903837688578274,
0.129714577882537, 0.146022440613998, 0.029358081257867, 0.0591809963859102,
0.0516785162644559, 0.112514101125709, 0.0795406083136827, 0.0944336305219004,
0.0936459039218517, 0.0726775751944748, 0.143200536740801, 0.0756616672734531,
0.0768093343124944, 0.192859469091138, 0.139677182309732, 0.731411842228994,
0.929139036438272, 0.731651960406345, 0.523572529910693, 0.728470709050467,
0.369407477451884, 0, 0.515261732169024, 0.405947063673079, 0.628429520644252,
0.219766065707624, 0.711686506777716, 0.108946532303133, 0.232324087684107,
0.294699860051154, 0.628620521453137, 0.37002902748092, 0.586009172701016,
0.606372233581375, 0.61229605162923, 0.529079057477617, 0.633565102904463,
0.867954936241549, 0.939942010041431)), class = c("tbl_df", "tbl",
"data.frame"), row.names = c(NA, -103L), .internal.selfref = <pointer: 0x0>, .Names = c("x",
"y", "steplength"))
And the code for the plot is
ggplot(data = Tracks_subset, aes(x = x,
y = y)) +
# stat_bin2d(bins = 10, aes(fill = ..density..)) + # blocky heat map
stat_density2d(aes(fill = ..level..,
alpha = ..level..),
bins = 20,
geom = 'polygon') +
xlim(-20,max(Tracks_subset$x)+20) + # Adds padding for polygons to have proper shape
ylim(-20,max(Tracks_subset$y)+20) +
coord_cartesian(xlim = c(0,max(Tracks_subset$x)), # Clips extra padding visually only
ylim = c(0,max(Tracks_subset$y)),
expand = FALSE) +
scale_fill_continuous(low = "white",
high = "red") +
theme_classic(base_size = 12,
base_family = "Droid Sans") +
theme(axis.text = element_text(color = "black"),
strip.text.y = element_blank(),
strip.background = element_rect(color = "white"),
legend.text = element_text(size = 12, family = "Droid Sans"),
legend.title = element_blank(),
legend.position = "none") +
facet_wrap(condition + lipase ~ video,
scales = "free")
Now my question is, how can I somehow incorporate the steplength parameter as either an extra dimension (e.g. instead of ..level.. I could somehow use steplength) or weight in the stat_density2d? I know it's possible for the stat_bin2d, but this gives me a very blocky appearance that I don't really like.