What have you tried so far? If you wrote code, but find it unsatisfactory, then please share that code so that it can be discussed.
Please provide a self-contained REPRoducible EXample (reprex)? A reprex makes it much easier for others to understand your issue and figure out how to help.
If you've never heard of a reprex before, you might want to start by reading this FAQ: