Plotting histograms with R; y axis keeps changing to frequency from proportion/probability
By : Bill Manning
Date : March 29 2020, 07:55 AM
this one helps. When you call plot on an object of class histogram (like c1), it calls the S3 method for the histogram. Namely, plot.histogram. You can see the code for this function if you type graphics:::plot.histogram and you can see its help under ?plot.histogram. The help file for that function states: code :
plot(c1, col=rgb(1,0,0,1/4), xlim=c(minx,maxx), main=paste(paramlab,"Group",groupnum,sep=" "),xlab="",freq=FALSE)# first histogram
plot(c2, col=rgb(0,0,1,1/4), xlim=c(minx,maxx), add=T, freq=FALSE)

Confusion on how the frequency axis when plotting the FFT magnitude is created
By : Raman Chhabra
Date : March 29 2020, 07:55 AM
I hope this helps . The reason why the range is between [Fs/2,Fs/2] is because Fs/2 is the Nyquist frequency. This is the largest possible frequency that has the ability of being visualized and what is ultimately present in your frequency decomposition. I also disagree with your comment where the range "could be between [0.25,0.25]". This is contrary to the definition of the Nyquist frequency. From signal processing theory, we know that we must sample by at least twice the bandwidth of the signal in order to properly reconstruct the signal. The bandwidth is defined as the largest possible frequency component that can be seen in your signal, which is also called the Nyquist Frequency. In other words: code :
Fs = 2*BW
BW = Fs / 2;
f = i * Fs / N, for i = 0, 1, 2, ..., N1
freqaxis=Fs*(linspace(0.5,0.5, 513); %// Change
freqaxis(end) = []; %// Change
freqaxis = linspace(Fs/2, Fs/2, 513);
freqaxis(end) = [];

Plotting a histogram with ggplot with only x values and frequency count, instead of usual frequency vector
By : Jae yeong
Date : March 29 2020, 07:55 AM
Hope that helps I have a dataframe for my for variable X, with the corresponding count of how many times each X value appears: , You can use stat="identity" with geom_bar. e.g. code :
testdt < data.frame(x = c(1,2,3,4,5,6), count = c(10, 20, 10, 5, 15, 25))
ggplot(data = testdt) + geom_bar(aes(x = x, y = count), stat = "identity")

Displaying yaxis in percentage format when plotting conditional frequency distibution
By : Hrishikesh Bharali
Date : March 29 2020, 07:55 AM

Plotting respiration signal in frequency domain on y axis while time is on x axis
By : Jason Li
Date : March 29 2020, 07:55 AM
wish helps you I have a respiration (breathing) signal and a sampling frequency of 25 Hz and need to detect where is the lowest breathing frequency on a time scale, which should tell me actually when the person became sleepy. Fourier transforms in its classical form doesn't give me much useful information. So, to clarify: the time of measurement should be on the xaxis and the breathing frequency should be on the yaxis. Then, I suppose, lower amplitudes of the signal will show the slower breathing. What should be done with the signal to plot it the way I need? , All credits for this code go to Star Strider. code :
D = load('respiratory.txt');
Fs = 25; % Sampling Frequency (Hz)
Fn = Fs/2; % Nyquist Frequency
Ts = 1/Fs; % Sampling Time (sec)
L = numel(D);
t = linspace(0, L, L)*Ts; % Time Vector (sec)
figure(1)
plot(t, D)
grid
% axis([0 60 850 750])
axis([xlim 850 750])
xlabel('Time')
ylabel('Amplitude')
FTD = fft(Dmean(D))/L; % Fourier Transform
Fv = linspace(0, 1, fix(L/2)+1)*Fn; % Frequency Vector
Iv = 1:numel(Fv); % Index Vector
figure(2)
plot(Fv, abs(FTD(Iv))*2)
grid
axis([0 2.5 ylim])
xlabel('Frequency (Hz)')
ylabel('Amplitude')
Wp = [0.35 0.65]/Fn; % Passband Frequency (Normalised)
Ws = [0.30 0.75]/Fn; % Stopband Frequency (Normalised)
Rp = 1; % Passband Ripple (dB)
Rs = 50; % Stopband Ripple (dB)
[n,Ws] = cheb2ord(Wp,Ws,Rp,Rs); % Filter Order
[z,p,k] = cheby2(n,Rs,Ws); % Filter Design, Sepcify Bandpass
[sos,g] = zp2sos(z,p,k); % Convert To SecondOrderSection For Stability
figure(3)
freqz(sos, 2^16, Fs) % Filter Bode Plot
D_filtered = filtfilt(sos, g, D); % Filter Signal
[pks,locs] = findpeaks(D_filtered, 'MinPeakDist',40);
figure(4)
plot(t, D_filtered)
hold on
plot(t(locs), pks, '^r')
hold off
grid
% axis([0 60 ylim])
axis([0 60 15 15])
xlabel('Time')
ylabel('Amplitude')
tdif = diff([0 t(locs)]); % Time Difference Between Peaks (sec)
Dfrq = 60./tdif; % Frequency (Respirations/Minute)
figure(5)
plot(t(locs), Dfrq)
grid
axis([xlim 10 40])
xlabel('Time (sec)')
ylabel('Frequency (minute^{1})')

