You need to change your code. It is not alphabet frequency. It is consensus matrix. Example code and image below:
library(Biostrings)
fastq <- readDNAStringSet("sample.fastq","fastq")
## At each position, base frequency
afmc=consensusMatrix(fastq, baseOnly=T,as.prob = T)
tafmc=t(afmc)
matplot(tafmc[,-5], type="l", lwd=2, xlab="Read Length", ylab= "Base frequency at each position")
legend(legend = colnames(tafmc)[-5],"topright",col=1:4, lty=1:4, lwd=2)
This is per-cycle base content. R is not good at, and is not designed for such task.
Why complicate life? Just use fastp to do the easiest and fastest way for such tasks, including QC and filtering. It will output the figures like what you want.
or use fastqc https://www.bioinformatics.babraham.ac.uk/projects/fastqc/ ?