How to assign one conditional label per stacked bar (not per stack) on time series ggplot in facet grid - time-series

I would love to have your input how to solve this issues.
I have a time series (x=date) ggplot with bars (y=cmass1), and my bars are on position="stack" using a factor (polymer) to display polymer types for each sample.
Each bar represents another sampling station (factor sample), and I would like to identify which bar is which station (factor "sample" in my data frame) and add the label above each bar.
I've come so far that I can show the "sample" labels, but then there appear multiple replicated labels (one for each data point in the stacked parts of the bar). But I need only one per bar!
Can someone help, how I can create one label per bar (above each bar) that identifies which sample it is (without manual annotation)?
Additional date display problem:
Also, on one date (11 November) I have two samples, and in this plot they are cumulated, but I would need them next to each - so two as stacked bars on one date (like with besides=TRUE, but that doesn't seem to work with stacked bars). Any help here?
I hope it is clear, and thanks so much for any help!
Cleo
The plot, where S1, S2 etc should be above each bar as a label
Dataframe view_partial
ggplot(Merg1[!(is.na(Merg1$campaign)),] ,
aes(date,y=cmass1,group_by(sample1), fill=polymer))+
geom_col(show.legend = T, alpha = 0.8, position="stack",
stat="identity")+
xlab("July 2021 November 2021 February 2022 July 2022") +
facet_grid(.~campaign, scales = "free_x",space = "free_x" )+
geom_point(aes(y=montsouris_mm*20 ),color="#A3009F",size=2.5, position="dodge")+
geom_point(aes(y=melun_mm*20 ),color="#558C8C",size=2.5, position="dodge")+
geom_point(aes(y=fauville_mm*20 ),color="#E8DB7D",size=2.5, position="dodge")+
scale_y_continuous(expand = c(0,0),limits=c(0, 1000), breaks = seq(0, 1000, by = 100),
sec.axis = sec_axis(~./20, name = "Precipitation (mm)",
breaks = seq(0, 50, by = 10))) +
scale_x_date(date_breaks = "1 day", labels = date_format("%d"))+
ylab(expression(bold(paste(~C[mass]~ (µg ~L^{-1}))))) +
theme(axis.text.x=element_text(color="black", size=12, angle=0, vjust=0.5),
axis.text.y=element_text(color="black", size=12, angle=0, vjust=0.5),
axis.ticks.x=element_blank(),
axis.title.x = element_text(size = 12,
color = "black",
face = "bold"),
strip.background = element_rect(color="white", fill="white", size=0.5,
linetype="solid"),
legend.text = element_text(color = "black",size = 12),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.background = element_rect(size = 0.5,colour="#D4CDCB",
fill="white" ,linetype = 'solid'),
legend.key.height= unit(0.2, 'cm'),
legend.key.width= unit(0.4, 'cm'))+
scale_fill_manual(name = "", values = MPcol, breaks = c("abs","acrylic", "acrylic paints", "alkyd","epoxy", "pa", "pan_acrylic fibre", "pe", "polyester", "pp", "ps", "pu", "pvac", "pvc", "sbr", "vinyl copolymer"),
labels=c("Acrylonitrile butadiene styrene (ABS)","Acrylic", "Acrylic paint", "Alkyd", "Epoxy", "Polyamide (PA)", "Pan acrylic fibre", "Polyethylene (PE)", "Polyester (PET)", "Polypropylene (PP)", "Polystyrene (PS)", "Polyurethane (PU)", "Polyvinyl acetate (PVAC)", "Poly vinyl chloride (PVC)", "Styrene butadiene rubber (SBR)", "Vinyl copolymere"))+
theme(legend.position = "bottom",
legend.background = element_rect(fill = "#FFFCFB", # Background
colour = 1),
legend.title = element_text(family = "sans",
color = "black",
size = 10,
face = 2)) +
theme(panel.grid.minor = element_line(color = "#D4CDCB",
size = 0.15,
linetype = 2))+
theme(strip.text.x = element_text(size=14, face="bold",
vjust = 2, color="black")) +
#geom_text( label = label1, vjust = -1, position = position_dodge(0.90), size = 3, hjust=-0.5)+
labs(title = "Microplastics",
subtitle = "Mass Concentrations by Polymer Types",
caption = "Still missing S4 repeated samples and M1 in Campaign D. S4 in Campaign C cumulated repetaed samples. MPs >300µm are excluded, also natural particles are excluded.",
tag = "Fig. 5-1") +
theme(plot.title = element_text(family = "serif", # Font family
face = "bold", # Font face
color = 1, # Font color
size = 16, # Font size
hjust = 1, # Horizontal adjustment
vjust = 1, # Vertical adjustment
angle = 0, # Font angle
lineheight = 1, # Line spacing
margin = margin(5, 0, 0, 0)), # Margins (t, r, b, l)
plot.subtitle = element_text(family = "serif",
hjust = 1, size=14), # Subtitle customization
plot.caption = element_text(hjust = 0.25, size =11,
family = "serif",face = "italic"), # Caption customization
plot.tag = element_text(face = "italic"), # Tag customization
plot.title.position = "plot", # Title and subtitle position ("plot" or "panel")
plot.caption.position = "panel", # Caption position ("plot" or "panel")
plot.tag.position = "top") # Tag position

Related

plotly joins points in wrong order

I have the following df (part)
"Date"
"2022-09-01" "2022-09-02" "2022-09-05" "2022-09-06" "2022-09-07" "2022-09-08" ....
"LogClose"
8.285728 8.274933 8.274933 8.270830 8.289004 8.295593 ....
"wielkoscDD"
0.00000000 -0.01073648 -0.01073648 -0.01478755 0.00000000 0.00000000 ....
I use:
p <- plot_ly(
df,
x = ~Date,
y = ~LogClose,
name = 'zamknięcie',
type = 'scatter',
mode = 'lines',
text = ~paste("zamknięcie :", Zamkniecie),
width = obrazek_szer,
height = obrazek_wyso)
but the second draw is correct
p <- plot_ly(
df,
x = ~Date,
y = ~wielkoscDD,
name = 'drawdown',
type = 'scatter',
mode = 'lines',
text = ~paste("drawdown : ", wielkoscDD),
width = obrazek_szer,
height = obrazek_wyso)
Additionaly on my Mac it works ok - on Windows there is chaos with the 1st chart.
rgds
Grzegorz

how to show all x label charts ios?

I make a custom numbering label, everything works great. the problem is when the number of entries is less than X-axis maximum, the chart doesn't show any lines.
lineChart.data = data
let leftAxis = lineChart.leftAxis
//set constant label range
leftAxis.forceLabelsEnabled = true
leftAxis.labelCount = 4
leftAxis.axisMinimum = 0
leftAxis.axisMaximum = 4.5
leftAxis.granularity = 1
leftAxis.axisLineWidth = 0
leftAxis.valueFormatter = YAxisData()
//x axis label
let bottomAxis = lineChart.xAxis
bottomAxis.axisMinimum = 1
bottomAxis.axisMaximum = 7.0
bottomAxis.labelCount = 7
bottomAxis.forceLabelsEnabled = true
bottomAxis.granularity = 1
bottomAxis.axisLineWidth = 0
bottomAxis.valueFormatter = XAxisData()
bottomAxis.labelHeight = 30
if I changed the number of entries to 7, it works fine.
I want a way to show all x labels even if the number of entries is less than 7!

Kivy: ScrollView squishes together the layout

I am new to Kivy and this is my first time trying to create a scrollView.
I am trying to do a 'Splitwise' ripoff where you can create expenses and let the app figure out who should pay who etc.
I am trying to create a method that opens a popup with all members and their balances as well as a button with the text 'Settle up'. Underneath the balances should be a list of all the registered debts, and you should be able to scroll down to see them all. The popup should also contain a 'Cancel'-button.
My problem is that my code doesn't enable scrolling, and also squishes together the content in the pop up. See picture.
All help highly appreciated!
See (messy) code below:
sbl_ret = GridLayout(cols = 1)
sbl_balances = GridLayout(cols = 3)
sbl_balances.add_widget(Label())
sbl_balances.add_widget(Label(text = 'Balances', font_size = '20sp', size_hint = (1,.2), color = backgroundColor, bold = True))
sbl_balances.add_widget(Label())
for member in self.members:
sbl_balances.add_widget(Label(text = member.getName(), font_size = 40, size_hint_y = None, height = 60))
sbl_balances.add_widget(Label(text = str(round(member.getBalance())) + ' kr', font_size = 40, size_hint_y = None, height = 60))
sbl2 = BoxLayout(orientation = 'vertical')
sbl2.add_widget(Label(size_hint = (1,.2)))
btn = Button(text = 'Settle up', background_color = buttonColor, bold = True, size_hint_y = None, height = 60)
btn.bind(on_press = lambda member: self.settleUp())
sbl2.add_widget(btn)
sbl2.add_widget(Label(size_hint = (1,.2)))
sbl_balances.add_widget(sbl2)
sbl_balances.add_widget(Label(size_hint = (.2,1)))
sbl_balances.add_widget(Label(text = 'Debts', font_size = '20sp', color = backgroundColor, bold = True))
sbl_balances.add_widget(Label(size_hint = (.2,1)))
for member in self.members:
for debt in member.getDebtList():
sbl_balances.add_widget(Label(size_hint = (.2,1)))
sbl_balances.add_widget(Label(size_hint_y = None, height = 60, text = debt.getToWhom().getName() + ' lent ' + str(debt.getAmount()) + ' SEK to ' + debt.getFromWhom().getName() + ' for ' + debt.getDescription(), font_size = 40))
sbl_balances.add_widget(Label(size_hint = (.2,1)))
sbl_balances.bind(minimum_height=sbl_balances.setter('height'))
sbl3 = BoxLayout(size_hint = (1,.15))
sbl3.add_widget(Label(size_hint = (.2,1)))
b = Button(text = 'Cancel', background_color = entryColor, size_hint_y = None, height = 150)
b.bind(on_press = lambda x: self.balanceDialog.dismiss())
sbl3.add_widget(b)
sbl3.add_widget(Label(size_hint = (.2,1)))
sv = ScrollView(do_scroll_x = False)
sv.add_widget(sbl_balances)
sbl_ret.add_widget(sv)
sbl_ret.add_widget(sbl3)
self.balanceDialog = Popup(title = 'Group view', content = sbl_ret, title_align = 'center',
title_color = backgroundColor, background_color = [0,0,0,.7], separator_height = 0, title_size = '28sp')
self.balanceDialog.open()
'''
Try adding size_hint_y=None to your code creating the GridLayout:
sbl_balances = GridLayout(cols = 3, size_hint_y=None)
See the documentation.

visNetwork: Rotate Graph arranged by Sugiyama Layout Algorithm

The following directed example graph is initially arranged with the visIgraphLayout("layout_with_sugiyama") algorithm:
library(dplyr)
library(visNetwork)
### create nodes
nodes <- tibble(id = c (1:13), group = c("D","D","D","A","C","C","C","C","A","A","C","A","A"),
label = c("only outgoing a","only outgoing b","only outgoing c","only incoming d","e","f","g","h","only incoming i","only incoming j","k","only incoming l","only incoming m")
### create edges
edges <- tibble(id = 1:12, from = c(1,1,2,3,3,7,6,8,8,5,11,11), to = c(5,6,5,4,7,8,8,9,11,10,12,13), arrows = "to")
### visualize graph
visNetwork(nodes, edges, main = "Test") %>%
visGroups(groupname = "A", size = 25, color = list(
background = "#005A83",
border = "#005A83")) %>%
visGroups(groupname = "C",size = 20, color = list(
background = "#994350",
border = "#000000")) %>%
visGroups(groupname = "D", size = 20, color = list(
background = "#44706F",
border = "#44706F")) %>%
visEdges(smooth = F, font = list("size"=5), color = "black") %>%
visLegend(width = 0.2) %>%
visIgraphLayout("layout_with_sugiyama") %>%
visInteraction(navigationButtons = TRUE) %>%
visPhysics(enabled = F)
The algorithm arranged the directed graph from the top to the bottom. I would like to visualize it from the left to the right. Hence, i only would like to rotate the graph by 90 degree to the left so that the green start-nodes are at the left and the blue end-nodes at the right. The legend etc. should not be affected.
Anybody an idea?
Found a solution due to bthieurmel on github:
graph <- visNetwork(nodes, edges, main = "Test") %>%
visGroups(groupname = "A", size = 25, color = list(
background = "#005A83",
border = "#005A83")) %>%
visGroups(groupname = "C",size = 20, color = list(
background = "#994350",
border = "#000000")) %>%
visGroups(groupname = "D", size = 20, color = list(
background = "#44706F",
border = "#44706F")) %>%
visEdges(smooth = F, font = list("size"=5), color = "black") %>%
visLegend(width = 0.2) %>%
visIgraphLayout("layout_with_sugiyama") %>%
visInteraction(navigationButtons = TRUE) %>%
visPhysics(enabled = F)
# access to the coordinates of the graph object with graph$nodes$x
# change the x and y coordinates
coord_y <- graph$x$nodes$y
graph$x$nodes$y <- graph$x$nodes$x
graph$x$nodes$x <- coord_y
graph

Standalone Indicator inTradingview

I have written this strategy with 3 MA (18ema, 50ema and 200sma)...
On my 15min chart (which I use for trading), if 18ema is below 50ema and 50ema is below 200sma and also 18ema MUST be below 50ema and 50ema MUST be below 200sma, then I plot red diamond on top of the chart like so:
Signal
This would be to look for short entry. The opposite would be for long... So far so good. What I am trying to do is instead of flipping through the chart to look for these setups, is there a way to do something like this instead:
standalone indicator
if 18ema is below 50ema and 50ema is below 200sma show Red diamond in M15 box just like above picture
if 18ema is below 50ema and 50ema is below 200sma show Red diamond in 1HR box just like above picture for currency pair AUDUSD... repeat the same for x amount of currency... again, just like the picture above. The bottom line is to have one place to look for the setup instead of flipping through the charts.
Here is the code that I have which I am currently using as shown on the very first picture above:
//#version=3
study(title="Inpulse Pullback 15", overlay=true)
s18ema = ema(close, 18) //slower 18EMA
s50ema = ema(close, 50) //medium 50EMA
s200sma = sma(close, 200) //slowest 200SMA
price = open[1]
s2 = security(tickerid, "60", s18ema) // 60 Minutes
s3 = security(tickerid, "60", s50ema) // 60 Minutes
s4 = security(tickerid, "60", s200sma) // 60 Minutes
plot(s18ema, title="EMA 18", color = aqua, linewidth = 1, transp=0)
plot(s50ema, title="EMA 50", color = orange, linewidth = 2, transp=0)
plot(s200sma, title="SMA 200", color = blue, linewidth = 2, transp=0)
longCondSig = (s18ema > s50ema) and (s50ema > s200sma) and (s2 > s3) and (s3 > s4)
shortCondSig = (s18ema < s50ema) and (s50ema < s200sma) and (s2 < s3) and (s3 < s4)
plotshape(series=longCondSig, title="Long", style=shape.diamond, location=location.top, color=#29ee0b, transp=0, size=size.small)
plotshape(series=shortCondSig, title="Short", style=shape.diamond, location=location.top, color=red, transp=0, size=size.small)
longEntry = longCondSig ==1
shortEntry = shortCondSig ==1
alertcondition(longEntry, "le", "le")
alertcondition(shortEntry, "se", "se")

Resources