R plotting fns refactored