Flashing factory image - all data still present
The apps and user data (everything that gets erased by factory reset) are contained within the /data partition (in fact, "factory reset" simply formats the /data partition). This partition is independent of other partitions. Android system is located on the /system partition. That means that, as long you don't wipe your /data partition, your apps and data will stay in the phone even when you change your Android version.

It is, however, recommended to wipe your /data partition when moving from one Android version to another, due to incompatibility issues.