Power BI :: how to draw a curve in a scattered chart? - plot

I have a graphic that we have created in Azure Log Analytics.
Such graphic is meant to show how a database is used based on 100 plot dots:
If I download those 100 points in a CSV they look like this:
percentageDTU
ResourceId
percentageTimeSpendAt
0
HelloResource
100.0697837
1
HelloResource
58.40893231
2
HelloResource
51.01186322
3
HelloResource
48.29030007
4
HelloResource
47.034194
5
HelloResource
45.77808793
6
HelloResource
42.9867411
7
HelloResource
32.65875785
8
HelloResource
29.23935799
9
HelloResource
27.70411724
10
HelloResource
25.47103978
11
HelloResource
23.65666434
12
HelloResource
22.3307746
13
HelloResource
21.35380321
14
HelloResource
20.93510119
15
HelloResource
19.9581298
16
HelloResource
18.63224006
17
HelloResource
18.2833217
18
HelloResource
16.74808095
19
HelloResource
15.77110956
20
HelloResource
14.86392184
21
HelloResource
14.02651779
22
HelloResource
13.25889742
23
HelloResource
12.3517097
24
HelloResource
12.21214236
25
HelloResource
11.51430565
26
HelloResource
11.1653873
27
HelloResource
10.88625262
28
HelloResource
9.839497558
29
HelloResource
9.281228193
30
HelloResource
9.141660851
31
HelloResource
9.00209351
33
HelloResource
8.932309839
34
HelloResource
8.862526169
36
HelloResource
8.513607816
38
HelloResource
8.443824145
39
HelloResource
8.234473133
40
HelloResource
8.094905792
41
HelloResource
7.81577111
42
HelloResource
7.606420098
43
HelloResource
7.536636427
44
HelloResource
7.327285415
45
HelloResource
7.048150733
46
HelloResource
6.908583391
48
HelloResource
6.559665038
50
HelloResource
6.420097697
52
HelloResource
6.350314027
53
HelloResource
3.489183531
54
HelloResource
3.140265178
55
HelloResource
3.070481507
56
HelloResource
3.000697837
58
HelloResource
2.861130495
59
HelloResource
2.791346825
67
HelloResource
2.651779484
71
HelloResource
2.512212142
76
HelloResource
2.442428472
78
HelloResource
2.372644801
79
HelloResource
2.30286113
93
HelloResource
2.23307746
95
HelloResource
2.163293789
96
HelloResource
2.093510119
97
HelloResource
2.023726448
98
HelloResource
1.953942777
99
HelloResource
1.605024424
100
HelloResource
1.325889742
but when I import them in Power BI and I select the scatter chart, as result, I only have 1 dot:
How can I draw a line instead?
You can also propose new visual to downloads, I will be happy to try it.

You mean like this?
Try a line chart instead.

Related

ifelse() not working correctly using mutate: R

I have a small doubt in ifelse confition. I've read numerous articles and tried different solutions but I'm not able to solve it. Please help me with it.
I have a column of numbers ranging from 0:59 and it recurs like this for 500 rows.
I am trying to create another column which divides 0:29 as 0 and 30:59 as 30.
Data:
> data$Minute
[1] 0 0 0 1 1 1 2 2 2 2 2 2 3 3 4 4 4 5 5 5 5 5 6 6 6 7 7 7 7 7 8 8 8 8 8 8 9
[38] 10 10 10 10 10 10 10 10 10 11 11 11 11 11 11 11 11 11 11 12 12 12 12 13 13 13 13 13 14 14 14 14 14 14 15 15 15
[75] 15 15 15 15 15 15 16 16 16 16 16 17 17 18 18 18 18 18 19 19 19 19 20 20 20 20 20 20 20 20 21 21 21 21 21 21 21
[112] 22 22 22 22 22 23 23 23 23 23 23 23 23 23 23 23 23 23 23 24 24 24 24 24 24 24 24 24 25 25 25 25 25 25 25 25 25
[149] 26 26 26 26 26 26 26 26 26 26 27 27 27 27 27 27 27 27 27 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 29
[186] 29 29 29 29 29 29 29 29 29 29 29 30 30 30 30 30 30 30 30 30 30 30 30 30 31 31 31 31 31 31 31 31 31 31 31 31 31
[223] 31 32 32 32 32 32 33 33 33 33 33 33 33 33 33 33 33 34 34 34 34 34 34 34 34 34 34 34 34 34 35 35 35 35 35 35 35
[260] 35 35 35 36 36 36 36 36 36 36 36 37 37 37 37 37 37 37 37 37 38 38 38 38 38 38 38 38 38 38 39 39 39 39 39 39 39
[297] 39 39 40 40 40 40 40 40 40 40 40 40 40 40 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 42 42 42 42 42 42 42
[334] 42 42 42 42 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 44 44 44 44 44 44 44 44 44 45 45 45 45 45 45 45 45
[371] 45 45 45 45 45 45 45 45 46 46 46 46 46 46 46 47 47 47 47 47 47 47 47 47 47 47 47 47 48 48 48 48 48 48 48 48 48
[408] 48 48 48 49 49 49 49 49 49 49 50 50 50 50 50 50 50 50 50 50 50 50 50 50 51 51 51 51 51 51 51 51 51 51 52 52 52
[445] 52 52 52 52 52 52 52 52 52 53 53 53 53 53 53 53 53 54 54 54 54 54 54 54 54 54 54 54 55 55 55 55 55 55 55 55 55
[482] 55 56 56 56 56 56 56 56 56 56 56 56 56 56 57 57 57 57 57 57 57 57 58 58 58 58 58 58 58 58 58 59 59 59 59 59 59
[519] 59 59 59 59 59 59 59 0 0 0 0
Code:
data<- data %>% mutate(Period = ifelse(((Minute >=0) && (Minute <= 30)),0, 30) )
While running this code, I am only getting Period value as 0 for all the data points. Can you please help me with this small issue?
Thanks in Advance!
Try this
data %>% mutate(Period = ifelse(minute <= 30, 0, 30))

Problems with column labels after importing a csv file

I'm trying to import an anova data set csv file into R using the read.csv function. When I import it the columns are labelled X........ Even though the csv file the column labels are clearly person, gender etc
I don't know why this is. I've copied the code below. Any help would be appreciated
read.csv("/Users/Desktop/R /anova data set.csv")
X.......
1 ;Person;gender;Age;Height;pre.weight;Diet;weight6weeks
2 ;25; ;41;171;60;2;60
3 ;26; ;32;174;103;2;103
4 ;1;0;22;159;58;1;54.2
5 ;2;0;46;192;60;1;54
6 ;3;0;55;170;64;1;63.3
7 ;4;0;33;171;64;1;61.1
8 ;5;0;50;170;65;1;62.2
9 ;6;0;50;201;66;1;64
10 ;7;0;37;174;67;1;65
11 ;8;0;28;176;69;1;60.5
12 ;9;0;28;165;70;1;68.1
13 ;10;0;45;165;70;1;66.9
14 ;11;0;60;173;72;1;70.5
15 ;12;0;48;156;72;1;69
16 ;13;0;41;163;72;1;68.4
17 ;14;0;37;167;82;1;81.1
18 ;27;0;44;174;58;2;60.1
19 ;28;0;37;172;58;2;56
20 ;29;0;41;165;59;2;57.3
21 ;30;0;43;171;61;2;56.7
22 ;31;0;20;169;62;2;55
23 ;32;0;51;174;63;2;62.4
24 ;33;0;31;163;63;2;60.3
25 ;34;0;54;173;63;2;59.4
26 ;35;0;50;166;65;2;62
27 ;36;0;48;163;66;2;64
28 ;37;0;16;165;68;2;63.8
29 ;38;0;37;167;68;2;63.3
30 ;39;0;30;161;76;2;72.7
31 ;40;0;29;169;77;2;77.5
32 ;52;0;51;165;60;3;53
33 ;53;0;35;169;62;3;56.4
34 ;54;0;21;159;64;3;60.6
35 ;55;0;22;169;65;3;58.2
36 ;56;0;36;160;66;3;58.2
37 ;57;0;20;169;67;3;61.6
38 ;58;0;35;163;67;3;60.2
39 ;59;0;45;155;69;3;61.8
40 ;60;0;58;141;70;3;63
41 ;61;0;37;170;70;3;62.7
42 ;62;0;31;170;72;3;71.1
43 ;63;0;35;171;72;3;64.4
44 ;64;0;56;171;73;3;68.9
45 ;65;0;48;153;75;3;68.7
46 ;66;0;41;157;76;3;71
47 ;15;1;39;168;71;1;71.6
48 ;16;1;31;158;72;1;70.9
49 ;17;1;40;173;74;1;69.5
50 ;18;1;50;160;78;1;73.9
51 ;19;1;43;162;80;1;71
52 ;20;1;25;165;80;1;77.6
53 ;21;1;52;177;83;1;79.1
54 ;22;1;42;166;85;1;81.5
55 ;23;1;39;166;87;1;81.9
56 ;24;1;40;190;88;1;84.5
57 ;41;1;51;191;71;2;66.8
58 ;42;1;38;199;75;2;72.6
59 ;43;1;54;196;75;2;69.2
60 ;44;1;33;190;76;2;72.5
61 ;45;1;45;160;78;2;72.7
62 ;46;1;37;194;78;2;76.3
63 ;47;1;44;163;79;2;73.6
64 ;48;1;40;171;79;2;72.9
65 ;49;1;37;198;79;2;71.1
66 ;50;1;39;180;80;2;81.4
67 ;51;1;31;182;80;2;75.7
68 ;67;1;36;155;71;3;68.5
69 ;68;1;47;179;73;3;72.1
70 ;69;1;29;166;76;3;72.5
71 ;70;1;37;173;78;3;77.5
72 ;71;1;31;177;78;3;75.2
73 ;72;1;26;179;78;3;69.4
74 ;73;1;40;179;79;3;74.5
75 ;74;1;35;183;83;3;80.2
76 ;75;1;49;177;84;3;79.9
77 ;76;1;28;164;85;3;79.7
78 ;77;1;40;167;87;3;77.8
79 ;78;1;51;175;88;3;81.9
colnames(aov)
[1] "X......."

Poisson distribution too narrow, negative binomial too broad

I'm trying to fit some count data for the number of fish purchased by anglers(grey in the image) with a distribution using optim in R. I've fit both a poisson (red) and negative binomial distribution (blue) but as you can see neither seems to be right. What should my next steps be for getting a better fit?
My graph:
#fit poisson curve to data using optim
minus.logL.s<-function(lambda, dat){
-sum(dpois(dat,lambda, log=TRUE))}
mle<-optim(par=45,fn=minus.logL.s, method="BFGS",hessian=T,dat=survey.responses.baitusers$fish.per.trip)
mle
#simulate data coming from a poisson distribution of mean 38
simspois<-as.data.frame(rpois(1000, 38))
colnames(simspois)<-("simulated_values")
#fit negative binomial curve
minus.logL.nb<-function(pars, dat){
mu<-pars[1]
size<-pars[2]
-sum(dnbinom(dat, mu=mu, size=size,log=TRUE))}
mlenb<-optim(par=c(mu=38,size=1),fn=minus.logL.nb, method="BFGS",hessian=T,dat=survey.responses.baitusers$fish.per.trip)
mlenb
simsnegbin<-as.data.frame(rnbinom(1000,size=4, mu=38))
colnames(simsnegbin)<-("simulated_valuesnb")
#graph both
graph<-ggplot(survey.responses.baitusers)+aes(fish.per.trip)+geom_histogram()+geom_smooth(data=simspois, aes(simulated_values), stat = "count",color="red")+geom_smooth(data=simsnegbin, aes(simulated_valuesnb), stat="count", color="blue")
graph
Output from negative binomial fitting:
$par
mu size
38.333338 4.107287
Output from poisson fitting:
$par
[1] 38.33333
My data:
> survey.responses.baitusers$fish.per.trip
[1] 15 34 42 38 8 38 21 29 58 29 40 35 33 51 50 40 8 45 44 45 34 57 8 28 63 54 22 44 65 54 54 15 12
[34] 42 59 40 43 95 80 15 54 19 44 27 53 95 21 38 40 13 25 27 79 38 85 40 33 74 34 77 34 34 33 35 89 34
[67] 34 37 16 60 17 21 18 37 34 27 30 62 48 35 55 50 23 32 56 34 11 21 34 48 15 34 26 54 8 95 8 58 54
[100] 44 34 47 35 13 21 53 52 52 40 40 33 8 15 15 25 41 63 34 38 87 14 68 58 59 34 55 24 24 35 33 21 8
[133] 8 15 51 48 8 21 39 29 50 54 62 16 54 33 58 22 49 40 30 51 21 19 51 40 34 27 40 45 80 69 8 42 33
[166] 62 40 82 17 14 30 61 45 70 33 33 16 49 32 34 31 31 18 64 33 39 21 56 40 52 71 34 30 27 54 8 64 16
[199] 54 127 13 51 40 33 63 31 30 63 56 57 77 46 64 22 34 50 66 33 34 59 45 16 21 60 58 15 64 29 40 44 29
[232] 8 21 16 72 34 49 57 34 34 15 33 54 40 32 33 95 107 49 64 59 64 37 70 45 16 16 40 19 53 34 39 21 36
[265] 34 17 8 34 51 13 20 34 21 38 36 36 41 34 83 27 8 45 29 34 21 37 44 15 50 25 27 8 27 19 24 40 8
[298] 28 36 24 40 21 70 20 34 21 46 16 20 8 33 34 54 44 77 80 15 34 40 29 48 59 29 8 15 47 45 21 41 23
[331] 34 51 14 40 25 45 64 59 107 21 59 27 56 48 34 45 59 35 30 37 32 8 51 11 48 64 32 8 52 14 20 18 8
[364] 53 52 53 33 34 48 62 34 34 8 46 39 21 33 34 40 49 52 19 24 29 43 19 29 27 46 52 29 51 61 16 17 35
[397] 34 40 25 28 34 42 66 35 49 35 51 66 21 51 45 14 53 22 42 64 8 48 28 66 52 40 29 34 34 41 59 34 52
[430] 16 32 20 35 8 8 21 49 40 33 16 24 8 42 23 63 26 21 33 8 23 112 57 8 46 18 67 34 30 33 40 43 57
[463] 60 33 14 27 44 21 31 30 27 49 57 69 66 22 28 55 11 43

R: Trimming/ Setting Boundaries on Filled.contour plot

I made a filled.contour plot and it cam out nicely, however I would like to trim out some of the hypotenuse of the triangle. Basically get rid of some of that yellow stripe along the hypotenuse.
Is there anyway I could go about doing that in R?
Here is my code:
library(akima)
> attach(asc)
>
> test<-interp(AvgDepth, AvgMaxDepth, Gs)
>
> filled.contour(test, color=heat.colors, xlab="Depth (m)", ylab="Maximum Depth (m)", ylim=c(5,90))
Here is my data set
AvgDepth AvgMaxDepth Gs
1 5 5 0.022706473
2 5 15 -0.006287207
3 15 15 -0.002071806
4 5 25 -0.002569846
5 15 25 -0.005698020
6 25 25 -0.013394740
7 5 35 -0.001723604
8 15 35 -0.004575939
9 25 35 -0.001260225
10 35 35 0.025808307
11 5 45 -0.008369802
12 15 45 -0.004661506
13 25 45 0.003438334
14 35 45 0.004066056
15 5 55 -0.004517855
16 15 55 0.001577937
17 25 55 -0.000761080
18 35 55 0.004597452
19 45 55 0.015894575
20 5 65 -0.003023326
21 15 65 0.001327518
22 25 65 -0.000967222
23 35 65 -0.005843258
24 45 65 -0.000534109
25 55 65 0.001292299
26 5 75 -0.003593511
27 15 75 0.000484908
28 25 75 -0.008013139
29 35 75 -0.013281240
30 45 75 -0.009767021
31 55 75 -0.019364488
32 65 75 -0.019202670
33 5 85 -0.004487259
34 15 85 -0.001588138
35 25 85 -0.004464418
36 35 85 -0.007797982
37 45 85 -0.013272495
38 55 85 -0.022616793
39 65 85 -0.017740362
40 75 85 0.012021166
41 5 95 0.002236271
42 15 95 0.002102761
43 25 95 -0.001748743
44 35 95 -0.003063959
45 45 95 -0.001264025
46 55 95 -0.004662023
47 65 95 0.002980029
48 75 95 0.015868836
49 85 95 0.008842697
50 95 95 0.036387641
Any Help is appreciated.
Thanks

Using barplot in R doesn't not match the data?

I want to use barplot (or any other better options) to plot the following data:
action_number times
1 1 13408
2 2 5550
3 3 2757
4 4 1782
5 5 1114
6 6 847
7 7 582
8 8 410
9 9 306
10 10 278
11 11 212
12 12 165
13 13 139
14 14 112
15 15 106
16 16 82
17 17 64
18 18 61
19 19 69
20 20 47
21 21 31
22 22 40
23 23 34
24 24 31
25 25 28
26 26 26
27 27 21
28 28 16
29 29 14
30 30 16
31 31 11
32 32 10
33 33 11
34 34 10
35 35 4
36 36 6
37 37 5
38 38 8
39 39 6
40 40 3
41 41 6
42 42 8
43 43 3
44 44 3
45 45 7
46 46 8
47 47 4
48 48 4
49 49 1
50 50 4
51 51 2
52 52 4
53 53 3
54 54 1
55 55 2
56 56 1
57 58 2
58 59 4
59 60 1
60 62 2
61 63 1
62 66 1
63 67 4
64 68 2
65 69 1
66 70 1
67 71 1
68 73 1
69 74 1
70 77 1
71 79 1
72 80 1
73 82 1
74 92 2
75 97 1
76 98 1
77 103 1
78 106 1
79 114 1
80 118 1
81 128 1
82 142 1
83 148 1
84 153 1
85 155 1
86 166 1
87 183 1
88 218 1
89 224 1
90 298 1
91 536 1
I am using the following, but it does not match the data correctly:
mp <- barplot(data$times,axes=FALSE,ylim=c(0,13408))
axis(1,at=data$action_number,labels=data$action_number)
#??? Should I use at=data$action_number to at=data$times
axis(2,seq(0,91,3),c(0:30))
![enter image description here][1]
Problems:
- the x-axis does not have 536, it only goes to 224
- the Y axis only shows one number
Can you please give me advice and if I should use any package?
still, unclear but may be something like this
barplot(data$times, xlab=data$action_number)
mp <- barplot(data$times,axes=FALSE,ylim=c(0,13408))
axis(1,at=seq(1,91,10),labels=data$action_number[seq(1,91,10)])
axis(2,seq(0,13408,500),seq(0,13408,500))

Resources